项目作者: azogue

项目描述 :
docker-compose flask API for serving psychrochart SVG files as a webcam for Home Assistant
高级语言: Python
项目地址: git://github.com/azogue/psychrocam.git
创建时间: 2018-05-31T09:22:01Z
项目社区:https://github.com/azogue/psychrocam

开源协议:MIT License

下载


psychrocam - A flask API for serving psychrochart SVG files like a webcam

Description

Psychrocam is a flask-celery-redis backend to create SVG psychrometric charts and overlay information from Home Assistant temperature and humidity sensors.
The main objective is to create a fake ‘webcam’ to add it as a Home Assistant generic camera, showing the psychrometric state in real-time.

HA View

This little project consist in 2 docker containers running:

  • A Redis database.
  • The main container, running supervisor to execute:
    • A celery worker
    • The celery beat, sending update tasks every scan_interval seconds
    • Gunicorn serving the flask application

Use with docker

The quickest way to get things running, just git clone this repository and run . run_compose.sh (notice the space between . and the script name, needed to preserve the exports).

You can edit that script to change the environment variables needed to run the container, or export them and run manually:

  1. export PORT=7777
  2. export LOGGING_LEVEL=WARNING
  3. export LOGGING_LEVEL_CELERY_WORKER=WARNING
  4. export LOGGING_LEVEL_CELERY_BEAT=WARNING
  5. export GUNICORN_NUM_WORKERS=2
  6. export CELERY_NUM_WORKERS=2
  7. export REDIS_PWD="customultrasecurepassword"
  8. export CUSTOM_PATH="./custom_config"
  9. # Use one or the other depending on your host architecture:
  10. # export LABEL=x64
  11. export LABEL=rpi3
  12. # Pull the container from docker hub:
  13. docker pull azogue/psychrocam:${LABEL}
  14. docker-compose up -d
  15. # Or build it
  16. docker-compose up -d --build

Customize

To get access to HomeAssistant and its sensors you need to write your own custom_config/custom_ha_sensors.yaml, with this schema:

  1. homeassistant:
  2. api_password: yourultrasecurehapassword
  3. host: 192.168.1.33
  4. port: 8123
  5. use_ssl: False
  6. history:
  7. delta_arrows: 10800 # seconds (:= 3h)
  8. scan_interval: 30
  9. location:
  10. altitude: 7
  11. # Optional pressure sensor to adapt atmospheric pressure:
  12. pressure_sensor: sensor.pressure_mb
  13. # Interior sensor pairs
  14. interior:
  15. Office:
  16. humidity: sensor.sensor_office_humidity
  17. style:
  18. alpha: 0.9
  19. color: '#8FBB46'
  20. markersize: 12
  21. temperature: sensor.sensor_office_temperature
  22. Living room:
  23. humidity: sensor.sensor_livingroom_humidity
  24. style:
  25. alpha: 0.9
  26. color: darkorange
  27. markersize: 12
  28. temperature: sensor.sensor_livingroom_temperature
  29. # Exterior sensor pairs
  30. exterior:
  31. Terraza:
  32. humidity: sensor.sensor_terraza_humidity
  33. style:
  34. alpha: 0.7
  35. color: '#5882FB'
  36. markersize: 12
  37. temperature: sensor.sensor_terraza_temperature
  38. Predicted:
  39. temperature: sensor.dark_sky_temperature
  40. humidity: sensor.dark_sky_humidity
  41. style:
  42. alpha: 0.6
  43. color: '#7996BB'
  44. markersize: 7

And go to host:7777/svgchart to show the last SVG psychrometric chart, or check /ha_states, /ha_config and /chartconfig.

Home Assistant integration

To see your psychrometric data in Home Assistant, add this generic camera:

  1. homeassistant:
  2. customize:
  3. camera.psychrometric_chart:
  4. friendly_name: Diagrama psicrométrico
  5. camera:
  6. - platform: generic
  7. name: psychrometric_chart
  8. still_image_url: http://192.168.1.33:7777/svgchart
  9. content_type: 'image/svg+xml'

You can add extra sensors to HA based on the evolution of watched states, that are present in other routes of this API (this is a work in progress).

In /ha_evolution you can access this JSON data:

  1. {
  2. "Office": {
  3. "first": {
  4. "HR [%]": 42.2,
  5. "T [°C]": 25.6,
  6. "ts": "2018-06-21T07:11:19.575077",
  7. "∆HR [%]": -0.2,
  8. "∆T [°C/h]": 0.766,
  9. "∆T [°C]": 2.3,
  10. "∆t [min]": 180.2
  11. },
  12. "last": {
  13. "HR [%]": 40.8,
  14. "T [°C]": 26.1
  15. },
  16. "mid": {
  17. "HR [%]": 40.8,
  18. "T [°C]": 26.1,
  19. "ts": "2018-06-21T08:41:06.489618",
  20. "∆HR [%]": 1.2,
  21. "∆T [°C/h]": 1.195,
  22. "∆T [°C]": 1.8,
  23. "∆t [min]": 90.4
  24. }
  25. },
  26. ... ,
  27. "Terraza": {
  28. "first": {
  29. "HR [%]": 41.8,
  30. "T [°C]": 26.9,
  31. "ts": "2018-06-21T07:11:31.281293",
  32. "∆HR [%]": -0.7,
  33. "∆T [°C/h]": 1.001,
  34. "∆T [°C]": 3.0,
  35. "∆t [min]": 179.9
  36. },
  37. "last": {
  38. "HR [%]": 24.3,
  39. "T [°C]": 37.1
  40. },
  41. "mid": {
  42. "HR [%]": 24.3,
  43. "T [°C]": 37.1,
  44. "ts": "2018-06-21T08:41:24.038771",
  45. "∆HR [%]": 16.8,
  46. "∆T [°C/h]": -4.8,
  47. "∆T [°C]": -7.2,
  48. "∆t [min]": 90.0
  49. }
  50. },
  51. "num_points": 720,
  52. "pressure_kPa": 101.71
  53. }

An example of integration would be adding some sensors showing the temperature rate change (to use them in automations). This can be done with a REST sensor and some template sensors exploiting its attributes:

  1. homeassistant:
  2. customize:
  3. sensor.psychrometric_evolution:
  4. hidden: True
  5. customize_glob:
  6. sensor.temp_change_*:
  7. icon: mdi:delta
  8. sensor:
  9. - platform: rest
  10. name: psychrometric_evolution
  11. resource: http://192.168.1.33:7777/ha_evolution
  12. unit_of_measurement: "sample"
  13. json_attributes:
  14. - pressure_kPa
  15. - Office
  16. - Salón
  17. - Terraza
  18. scan_interval: 30
  19. value_template: '{{ value_json.num_points | int }}'
  20. - platform: template
  21. sensors:
  22. temp_change_office:
  23. friendly_name: '∆T Office'
  24. value_template: '{% if "Office" in states.sensor.psychrometric_evolution.attributes %}{{ states.sensor.psychrometric_evolution.attributes["Office"]["first"]["∆T [°C/h]"] | round(2) }}{% endif %}'
  25. unit_of_measurement: '°C/h'
  26. temp_change_livingroom:
  27. friendly_name: '∆T Salón'
  28. value_template: '{% if "Salón" in states.sensor.psychrometric_evolution.attributes %}{{ states.sensor.psychrometric_evolution.attributes["Salón"]["first"]["∆T [°C/h]"] | round(2) }}{% endif %}'
  29. unit_of_measurement: '°C/h'
  30. temp_change_terraza:
  31. friendly_name: '∆T Terraza'
  32. value_template: '{% if "Terraza" in states.sensor.psychrometric_evolution.attributes %}{{ states.sensor.psychrometric_evolution.attributes["Terraza"]["first"]["∆T [°C/h]"] | round(2) }}{% endif %}'
  33. unit_of_measurement: '°C/h'

TODO

  • Change the way it access to the Home Assistant event stream.
  • Convert this in a HASS.io addon or a HA component
  • Use a better UI in HA (Lovelace future?)
  • Use sun position and orientations to predict irradiation power (ASHRAE clear sky model) for windows and walls and publish new HA sensors