I have a problem with a pretty straightforward automation script. The problem is that the script not always triggers (while the conditions are true);
Sometimes it works for 3 days, and sometimes it only works one day. To get the script / trigger working again i need to restart HomeAssistant or i need to reload the automations.
The script:
alias: Turn on fan if humidity is > 75 and temperature > 30 and fan is off
description: ''
trigger:
- platform: template
value_template: '{{ states.sensor.room_sensor_mijia_humidity | float > 75 }}'
condition:
- condition: template
value_template: '{{ states.sensor.sonoffth_fan_ds18b20_temperature.state | float > 30 }}'
- condition: state
entity_id: switch.sonofftouch_t2afan
state: 'off'
action:
- device_id: sdf3fd3ssd4fsdf
domain: switch
entity_id: switch.sonofftouch_t2afan
type: turn_on
When the script doesn’t work i always check the conditions. The conditions are truebut the script will not always trigger.
I can fix this with a time_pattern trigger but is not a real nice solution. Right?
I disagree with @Kdem, you need to compare ‘numbers’ (be they floats or integers) else you will find :
‘2’ > ‘10’ == True
However this will only trigger if the value was less than 75 and moves to greater than 75, this should be fine for ‘normal’ operations but if you restart (etc.) with the value already above 75, it won’t.
You should also be using initialisation proof syntax, so instead of : -
I was talking about the | float in the condition value template, not the trigger. Also you left the .state out in the template editor, its in your original code.
Okay, check. This script will only trigger when the shower is on, so for example in the morning the value is always lower then 75. However; sometimes it will not trigger but the conditions are both true… any explanation or solution for this?
Numeric state trigger and condition would be what you’re really looking for here.
alias: Turn on fan if humidity is > 75 and temperature > 30 and fan is off
description: ''
trigger:
- platform: numeric_state
entity_id: sensor.room_sensor_mijia_humidity
above: 75
condition:
- condition: numeric_state
entity_id: sensor.sonoffth_fan_ds18b20_temperature
above: 30
- condition: state
entity_id: switch.sonofftouch_t2afan
state: 'off'
action:
- device_id: sdf3fd3ssd4fsdf
domain: switch
entity_id: switch.sonofftouch_t2afan
type: turn_on
If what you show in the first box is true, and there’s not a typo, then this would seem to imply the problem is not the trigger or the conditions, but rather the sensor isn’t always available. You should check to make sure that sensor is reliable and doesn’t disappear sometimes.
Agreed that’s a better way to write the automation, but they work basically identically to the template trigger & condition in the OP. I can’t see how it would really make a difference in this case.
You could instead create a binary sensor, with or without sensor.time as an entity id, or better still, one of each, then perhaps create another to check if they ever disagree.
Monitor these for a bit and see which you prefer.
Note the binary_sensor will always display the correct sense (if it’s working) ie it won’t be bothered about the transitions. (you could then use the better (???) one to drive a template switch to control your fan)
The above would also allow you to gather evidence for your supposition regarding a ‘bug’
Glad you got it sorted. Even gladder (is that even a word???) that you have added skills to your repertoire AND searched the docs.
Can you post your two sensors for reference and checking ?
Did you create a template switch or are you just using automations ?
Monitor them and report back with anything interesting.