Triggers and Conditions!

Who ever invented the trigger and conditions must have been taking drugs or had a degree in thermonuclear dynamics. It is the most confusing part of Home Assistant I have come across yet.
I am trying to parse the most simple of tasks but am having absolutely no success whatsoever…I have spent 8 hours manipulating text, reading the explanations and still no joy. Please could somebody put me out of my misery.
I have a window in my attic with a fibaro sensor on it for either open or closed. I have the yr weather sensor (I would like others too like the met office so that I can use an OR statement for cross reference but won’t add that just yet) and am saying if it detects precipitation of greater than 0.1mm and the window is open to send a notify message to my phone.
The logic isn’t working at present and will only trigger if its raining when I open the window…I wan’t it to be if the window is open and then it rains it triggers…I have moved the contents of the conditions and the trigger around with no joy !

  - alias: "Window Open And Rain Alarm"
trigger:
  - platform: numeric_state
    entity_id: sensor.yr_precipitation
    value_template: '{{ state.sensor.yr_precipitation.state > 0.1 }}'
condition:
    condition: state
    entity_id: binary_sensor.fibaro_system_fgk101_door_opening_sensor_sensor
    state: 'on'
action:
  - service: notify.notify
    data:
      message: "RAIN - Close The Roof Windows"
      data:
        push:
          badge: 1

It can be daunting, but there’s plenty of help available.

So here are some assumptions:

  1. you have a functioning yr precipitation sensor that returns a numeric value
    you can test this assumption by pasting this code into the template editor:

    {{states.sensor.yr_precipitation.state > 0}}

    if this evaluates to true or false, then you have a working sensor. If it returns blank, then you have a problem with your sensor.

  2. You have a working door sensor with the state set to ‘on’ when the window is open.
    you can test this assumption by opening the window, then pasting this code into the template editor:

    {{states.binary_sensor.fibaro_system_fgk101_door_opening_sensor_sensor.state == 'on'}}

    again, if this returns true or false, you have a working sensor. If it is blank, you have a problem

  3. Finally, I assume you have a working notify component.
    You can test your notify component by going to the services tab in developer tools and choosing notify from the domain and notify from the service, then entering this as service data:

    {“message”: “RAIN - Close The Roof Windows”}

Now, with all those assumptions tested, this is code that should work for your automation:

- alias: "Window Open And Rain Alarm"
  trigger:
    - platform: numeric_state
      entity_id: sensor.yr_precipitation
      above: 0.1
  condition:
    condition: state
    entity_id: binary_sensor.fibaro_system_fgk101_door_opening_sensor_sensor
    state: 'on'
  action:
    - service: notify.notify
      data:
        message: "RAIN - Close The Roof Windows"
        data:
          push:
            badge: 1

Hi Treno
Thanks for the reply…I am going mad…I have checked the physical sensor with your script in the template editor and the fibaro sensor works as described but the code for taking the weather precipitation sensor returns nothing using

{{states.sensor.yr_precipitation.state > 0}}

in the template editor no matter what number I enter.

However if I remove the operator and put the following in the editor

{{states.sensor.yr_precipitation.state }}

this reports the value of whatever the precipitation is reporting…so what am I doing wrong

That means the sensor.yr_precipitation sensor is not a number, it’s a string.
So try this:

{{(states.sensor.yr_precipitation.state | float )> 0}}

And that means you have to update your automation as well.

- alias: "Window Open And Rain Alarm"
  trigger:
    - platform: template
      value_template: "{{(states.sensor.yr_precipitation.state | float) > 0.1}}"
  condition:
    condition: state
    entity_id: binary_sensor.fibaro_system_fgk101_door_opening_sensor_sensor
    state: 'on'
  action:
    - service: notify.notify
      data:
        message: "RAIN - Close The Roof Windows"
        data:
          push:
            badge: 1

Ok so I have copied your code and can confirm the yr precipitation sensor works now has true or false when the value is over 0.1. But still it doesn’t work.
I can manually trigger the event and receive a notification so I know that part works…it’s all so confusing.

I recommend making the case as simple as possible for confirmation purposes.
Remove the condition from your automation and get that working first.

I just wanted to say thanks for @treno. This made sense to me know. I have always been confused by this as well.

1 Like

Treno
You are fantastic…I have no idea what happened. I removed the condition. Which proved the yr precipitation was working and then entered the condition again as you suggested and this time it worked. So there must have been a typo somewhere. So annoying !!
I am so grateful for your assistance with this. Where can I find out more information about float values. It makes sense now but it is a little like black magic !! I would never have known how to solve that.
Thanks once again…
Brinzlee

This is the place to start when it comes to templating…