I’m trying to setup a rule and I believe I can sort everything else I require once I have this sorted, basically I will have other time and date related rules to turn this automation on and off as required.
I have my temp sensor updating every 10 seconds, I want that update to be the trigger, the conditions are that the climate has to be currently turned off. I have input number sliders to set variable targets for min and for max. I want a script to run when the temp returns a reading higher than the max target temp. I feel its just how I’ve written my if statement… can someone please help?
id: cool_bedroom_night
alias: Cool Bedroom Night
trigger:
entity_id: sensor.bedroom_temperature
platform: state
condition:
condition: state
entity_id: climate.bedroom_ac
state: ‘off’
action:
service: script.turn_on
data_template:
entity_id: >
{%- if sensor.bedroom_temperature.state | int > input_number.bedroom_max_target_temp | int -%}
script.cool_bedroom
{%- endif -%}
{% if states('sensor.bedroom_temperature') | int > states('input_number.bedroom_max_target_temp') | int %}
I would actually use that as a condition template.
You could also use | float if you want the cooling to turn on when the bedroom temperature is a fraction of a degree above the set point, rather than one degree above as will happen with | int
I guess I could use it as a condition but I wasn’t sure how to write it as one.
Thanks for the tip on using float instead. Works a treat!!
As I’m using a custom climate (2 actually) turning it off was a bit painful but I got there, now I have summer and winter time schedules with variable target temps as well as an away mode “kill switch”.
There should be more documentation of if/else/endif statements in my opinion, they aren’t very consistent and a few more examples would help a lot of people out.
This avoids running an action section with no actions as in your original configuration if the temperature template does not evaluate to true.
In future could you please format your pasted code segments as per the blue banner at the top of the page. It not only makes the code easier to read but also easier to spot indentation problems (very important in YAML).
Actually the way you are doing it at the moment is worse than executing no actions. If the temperature template evaluates to false you will be calling a script.turn_on with no arguments (check you log for errors from this). Best to do it with the template in the condition.