Template Help for a newbie

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.

Thanks,
Brian

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.

I am trying to create an automation based off of the if statement. if temp is above 40 and heat mode is on, send a notification to my phone.

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 %}

Thanks, i am just trying to figure it out. I appreciate the help!

this goes in the configuration.yaml file? If so, it says that integration trigger: not found. Sorry

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

Is there a reason you would not want to use the Automation editor?

besides not knowing about it…no

Thanks again

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?

Are you sure the sensor is actually functional?

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”.

I did copy what you sent, but when i run it, it always sends a notification.

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') }}
action:
  - service: notify.mobile_app_brian_iphone1
    data:
      message: shutdown the wood burner.
      title: Temperature is above 40 Degrees!
mode: single

the 60 was a test to see if it would send the notification

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.

yep, that’s what i was doing. How can i test this then?

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”.

no matter what i do it always triggers the notification

Isn’t that what the Automation is suppose to do?

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

that worked… Thanks