I have an electric heater in a garden shed.
The heater is plugged into a Tuya Wifi plug.
I have a sonoff temperature sensor in the shed.
I have a sonoff door sensor on the shed door (detects door state as open or closed).
I want the heater on if the temperature is less than 5 C AND the door is closed.
I want the heater off if the temperature is greater than 5 C OR the door is open.
My automation partially works. Sometimes the heater remains on when it should be off. Sometimes the heater remains off when it should be on.
I have two automations.
Automation A:
Trigger:
Temp above 5C
Door open
Condition:
None
Action:
Turn off heater
Automation B:
Trigger:
Temp less than 5 C
Condition:
Door is closed
Action:
Turn on heater
Automation A:
Trigger:
Temp above 5C
Condition:
None
Action:
IF door open
turn heater off
Automation B:
Trigger:
Temp less than 5 C
Condition:
None
Action:
If door closed
turn on heater
else
turn off heater```
It’s neither. As a first problem, a binary sensor’s state is “on” or “off”, not “open” or “closed”. And that error wouldn’t have been apparent in pseudocode.
alias: Shed light off when door is open or temp > 10 C
description: Shed light off when door is open or temp > 10 C
triggers:
- type: temperature
device_id: 34
entity_id: 04
domain: sensor
trigger: device
above: 10
for:
hours: 0
minutes: 0
seconds: 5
- type: opened
device_id: 20
entity_id: a1
domain: binary_sensor
trigger: device
for:
hours: 0
minutes: 0
seconds: 5
conditions: []
actions:
- type: turn_off
device_id: 7e
entity_id: f6
domain: switch
mode: restart
alias: Shed light on when door is closed and temp < 10 C
description: Shed light on when door is closed and temp < 10 C
triggers:
- type: not_opened
device_id: 20
entity_id: a1
domain: binary_sensor
trigger: device
for:
hours: 0
minutes: 0
seconds: 1
conditions:
- condition: numeric_state
entity_id: sensor.th_disc_shed_snzb_02p_temperature_2
below: 10
actions:
- type: turn_on
device_id: 7e
entity_id: f6
domain: switch
mode: restart
Sort of. I’m trying to get my head around YAML. I’m beginning to think YAML is event driven rather than state. I’ve programmed in C and Visual Basic years ago so YAML is new to me.
YAML is the interface to HA and isn’t really a language. Script ing that allows you to talk to the core more like.
Automation triggers are all events in one form or another. The state has to change and that event if it matches the requirements triggers the rest to run.
The state doesn’t matter unless a change it makes matches the trigger pattern, and then it fires.
So yes, you are getting the idea.