Hi everyone,
I am running into a weird issue whilst writing up a new automation:
automation heater_on:
- id: heater_on
alias: "Start heater if the temperature in the living room falls below 22C degrees and someone is home"
trigger:
- platform: template
value_template: "{{ states('sensor.motion_sensor_living_room_temperature_measurement') | float < 22 }}"
condition:
- condition: or
conditions:
# At least one iPhone needs to be connected to the wifi - i.e. someone is home
- condition: template
value_template: "{{ is_state('sensor.iphone_ssid', 'MyInternet') }}"
- condition: template
value_template: "{{ is_state('sensor.iphone_2_ssid', 'MyInternet') }}"
action:
- service: notify.mobile_app_iphone
data:
title: "Turning fan on"
message: "Turning on fan as it is now less than 22 degrees in the living room"
# Turn on the fan
- service: homeassistant.turn_on
target:
entity_id: switch.fan
The above automation never gets triggered (I am testing through the Dev Menu > States > Setting the state of the temperature sensor).
After a few different tries, I realised that the issue is with the platform: template trigger. When I replace the trigger with the below as a test, it works perfectly:
- platform: state
entity_id: sensor.motion_sensor_living_room_temperature_measurement
from: '14'
to: '16'
The above works because I manually set the state to 14, and then to 16.
Now you might be wondering why I am using template where I could just do:
- platform: numeric_state
entity_id: sensor.motion_sensor_living_room_temperature_measurement
below: 22
The issue is that for some reason, the temperature state variable comes back as a string (verified through the templates debugger menu).
Any help would be greatly appreciated!