My automation is not working. Weather condition

Hi, i’m new to automations.

I want to start my sprinkler every day at 6:30 for 30 minutes when weather is not predicting rain.

What I did: I have created a sensor with the weather forecast. Works so far. But the automation trace tells me the condition is not working.

Any ideas?

Sorry I am only allowed to add one picture

The attribute is existing:

Created this way:

Replace the Numeric State Condition with this Template Condition.

  - condition: template 
    value_template: "{{ 0 <= state_attr('sensor.weather_prediction', 'precipitation') | float(0) <= 0.5 }}"

It checks if the value of precipitation, which is part of sensor.weather_prediction’s attributes, is greater than or equal to 0 and less than or equal to 0.5.

So if its value is 0 then it should pass the Template Condition.


NOTE

Go to Developer Tools > States, find the sensor in the list and confirm its attribute is spelled precipitation. If it’s spelled Precipitation then you must correct the example I posted.

Similarly, confirm the sensor’s entity_id is correct because it’s truncated in the screenshot you posted. I made an assumption it’s sensor.weather_prediction

1 Like

Will try out as soon as the kids are sleeping.

Cheers

You can test the template in the Template Editor.

Copy-paste the following template into Developer Tools-> Template.

{{ 0 <= state_attr('sensor.weather_prediction', 'precipitation') | float(0) <= 0.5 }}

It will report True if the value of precipitation is between 0 and 0.5, inclusively.

If it reports False then check precipitation’s value
with this template:

{{ state_attr('sensor.weather_prediction', 'precipitation') }}
1 Like

Haha, works! Thanks @123
But one question. Why do I have to use “template”?
sensor.weather_prediction is a sensor and a sensor is an entity.
It seems that I do not understand the concept of “template” here.

How to decide when to choose theh correct type within automations?

1 Like

You could use the Numeric state condition without the above component… unless precipitation can report negative numbers it shouldn’t cause any false positives.

- condition: numeric_state
  entity_id: sensor.weather_prediction
  attribute: precipitation
  below: 0.5

In your original condition, the issue was that 0 isn’t above 0, so the condition failed. Taras’ template condition provides for “>=” where the Numeric state condition only provides “>”.

1 Like

Thanks @123 This is good to know.

More important - forgot to ask:
Is it a good practice to turn the automation off with the delay? Or is there a more secure way to implement it?

Generally speaking, I minimize the use of delay or, when I do use it, ensure it is a very short delay (less than a few minutes).

The reason is because if Home Assistant is restarted while the delay is counting down, all automations are immediately terminated. That means your automation wouldn’t execute the switch.turn_off command.

For your application, simply create two Time Triggers, one for 06:30 and the other for 07:00. Identify each one with a trigger id.

The following example turns on the switch at 06:30, and off at 07:00, but only if precipitation is less than or equal to 0.5.

alias: example
triggers:
  - id: 'on'
    trigger: time
    at: '06:30:00'
  - id: 'off'
    trigger: time
    at: '07:00:00'
conditions: 
  - condition: template 
      value_template: "{{ 0 <= state_attr('sensor.weather_prediction', 'precipitation') | float(0) <= 0.5 }}"
actions:
  - action: switch.turn{{ trigger.id }}"
    target:
      entity_id: switch.bewasserung_ven

You screenshot doesn’t show the switch’s complete entity_id so my example uses only what’s visible (switch.bewasserung_ven).

Looks so easy. Thanks. Will do it Like that.

This was also my concern that it could happen that the sprinkler will run forever. What I did was to create a security mechanism: at 9am just send a turn off to the sprinkler.

You don’t need to wait for 2 hours of water being wasted before turning it off. At the very least, you can set the sprinkler to turn off at 07:10 in your separate automation.

Otherwise just set the automation to turn off your sprinkler if it’s been on for 40 mins.