So really interested in the collective view on the above ways of creating automations. Here is my progression -
- I started with YAML, as I am sure most do. Its simple, but verbose to do even quite simple things.
- I moved to node-red to create my more complex automations, especially interfacing with Google via nora, but I guess visual programming just isn’t my thing!
- Looking for a more traditional programming environment I came across AppDaemon and pyscript. AppDaemon looked more complex to setup, so I am currently trying out pyscript. In the space of a few days I have moved many of my automations to it (even the most complex ones).
Obviously YAML is supported by core HA, and both node-red and pyscript are custom components. AppDaemon I think is classified as an add-on.
Here is an example pyscript automation to turn on/off an extractor fan based on CO and humidity levels, which is quite complex in YAML!
# Utility room extractor fan
@state_trigger("sensor.utility_room_multisensor_humidity_air")
@state_trigger("binary_sensor.utility_room_sensor_co_co_alarm")
@time_trigger("once(08:00)","once(22:00)")
def extractor_fan():
if (binary_sensor.utility_room_sensor_co_co_alarm == 'on'):
if (switch.utility_room_extractor_fan_switch_1 == "off"):
switch.turn_on(entity_id="switch.utility_room_extractor_fan_switch_1")
else:
if (float(sensor.utility_room_multisensor_humidity_air)
> float(sensor.hall_multisensor_humidity_air) + 10.0
and is_time_between(time(8,0), time(22,0))):
if (switch.utility_room_extractor_fan_switch_1 == "off"):
switch.turn_on(entity_id="switch.utility_room_extractor_fan_switch_1")
else:
if (switch.utility_room_extractor_fan_switch_1 == "on"):
switch.turn_off(entity_id="switch.utility_room_extractor_fan_switch_1")
Followed by a YAML version to do the same thing:
- id: '1666726828122'
alias: Extractor fan
description: ''
trigger:
- platform: state
entity_id: sensor.utility_room_multisensor_humidity_air
- platform: state
entity_id:
- binary_sensor.utility_room_sensor_co_co_alarm
- platform: time
at: '22:00:00'
- platform: time
at: 08:00:00
condition: []
action:
- if:
- condition: or
conditions:
- condition: state
entity_id: binary_sensor.utility_room_sensor_co_co_alarm
state: 'on'
- condition: and
conditions:
- condition: numeric_state
entity_id: sensor.utility_room_multisensor_humidity_air
above: sensor.hall_multisensor_humidity_air
value_template: '{{ float(state.state,0) - 10 }}'
- condition: time
after: 08:00:00
before: '22:00:00'
- condition: state
entity_id: switch.utility_room_extractor_fan_switch_1
state: 'off'
then:
- service: switch.turn_on
data: {}
target:
entity_id: switch.utility_room_extractor_fan_switch_1
else:
- if:
- condition: state
entity_id: switch.utility_room_extractor_fan_switch_1
state: 'on'
then:
- service: switch.turn_off
data: {}
target:
entity_id: switch.utility_room_extractor_fan_switch_1
mode: single
So where I have ended up currently:
- If it can be done with a blueprint (e.g. motion->light on) then it stays in YAML
- If it interfaces to Google, I use nora, so node-red
- Everything else in pyscript
It seems surprising that more people aren’t using pyscript (judging by forum posts), but perhaps they are using AppDaemon already and I just haven’t got there yet