You’ve just got a couple little issues…
- There is no reason to use an
if
statement for your examples. - The function is
states()
notstate()
- You need to provide a default value for many filters, including
float
.
trigger:
- platform: template
value_template: >-
{{ states('sensor.main_bathroom_humidity') | float(0) > 55 }}
id: Above 55% Humidity
- platform: template
value_template: >-
{{ states('sensor.main_bathroom_humidity') | float(0) < 55 }}
id: Below 55% Humidity
However, it’s not really necessary to use template triggers here, since the basic Numeric state trigger will work fine… And that will also allow you to easily add a for
variable so your fan doesn’t bounce on and off if the humidity is hovering around your setpoint.
trigger:
- platform: numeric_state
entity_id: sensor.main_bathroom_humidity
above: 55
id: 'on'
for: "00:01:00"
- platform: numeric_state
entity_id: sensor.main_bathroom_humidity
below: 55
id: 'off'
for: "00:01:00"
condition: []
action:
- service: switch.turn_{{ trigger.id }}
target:
entity_id: switch.main_bathroom_fan