I am extremely new to HA and i am trying to write my first automation basically i think i need a template that checks two sensors and sends me a notification to me on my Cell phone.
Here is my 1st crack: the if statement works `
template:
sensor:
state: >
{% if states(“sensor.outdoor_temperature”)|float > 40 and states(“climate.home”) == ‘heat’ %}
action:
- service: notify.mobile_app_brian_iphone1
data:
message: shutdown the wood burner.
title: Temperature is above 40 Degrees!
mode: single
{% endif %} `
Not sure really how to do this and any help is greatly appreciated.
You have mixed the configuration for a Template sensor with that used for an Automation… which do you want?
Also please format configurations and code in your posts using ``` at the beginning and end. In addition to being easier to read it prevents quote marks get messed up when being copied and pasted.
For this you do not need an if statement. Template triggers fire when they evaluate to true, so your template needs to be set up to evaluate as true or false:
trigger:
- platform: template
value_template: >
{{ states('sensor.outdoor_temperature') | float(0) > 40
and is_state('climate.home', 'heat') }}
action:
- service: notify.mobile_app_brian_iphone1
data:
message: shutdown the wood burner.
title: Temperature is above 40 Degrees!
mode: single
To do the same with an if statement, the template would need to be:
{% if states('sensor.outdoor_temperature') | float(0) > 40 and is_state('climate.home', 'heat') %}
true
{% else %}
false
{% endif %}
Automations can be placed in configuration.yaml under the heading automation:, but I would suggest using the Automation editor, especially if you are new to Home Assistant. If you need a primer on translating yaml automation configurations into the Automation editor, there is one available on the ResinChem Tech Youtube Channel
so i tried to use the automation editor for this but the sensors do not show up under devices or any other place. That’s why i was trying to use the code Why can i not see the sensors in the automation area?
Keep in mind that not all entities are devices… that is one of reasons why there are 17 types of triggers. You need to select “Template” as your trigger type. Optionally, you can just copy/paste what I provided earlier into the automation editor after clicking the menu at the top right of the page and selecting “Edit in YAML”.
What do you mean by this? Do you mean you are clicking the “Run” option in the menu? That button is just for testing Actions, it bypasses the trigger and any conditions that have been set.
If you go to Developer tools > States
Select “sensor.cavallina_inn_outdoor_temperature” & you should be able to change the state from there.
do the same for “climate.cavallina_inn”.
If you want to test if the automation works when those sensors are in that state normally, you will need to trigger those sensors naturally.
You could add the trigger as condition as well (I do not recommend this extra complexity for a beginner).
Then test it using
Developer tools > Services > Automation: Trigger
Unselect “Skip conditions”
alias: Pellet stove
description: ""
trigger:
- platform: template
value_template: >
{{ states('sensor.cavallina_inn_outdoor_temperature') | float(0) > 60 and
is_state('climate.cavallina_inn', 'heat') }}
condition:
- condition: template
value_template: >
{{ states('sensor.cavallina_inn_outdoor_temperature') | float(0) > 60 and
is_state('climate.cavallina_inn', 'heat') }}
action:
- service: notify.mobile_app_brian_iphone1
data:
message: shutdown the wood burner.
title: Temperature is above 40 Degrees!
mode: single