Are you doing this via the UI or directly in YAML? What you want to do is connect multiple conditions with OR statements to achieve what you are looking for. The trigger should be what starts thing but the condition makes the decision. So your trigger could be when any of those states change and the conditions would be OR’s:
Oh thanks for the answers.
I’m doing in YAML because i think it’s cleaner. I completely forgot the “or” statement.
What if in the trigger i set like this:
trigger:
- platform: state
entity_id: weather.casa
to: sunny
- platform: state
entity_id: weather.casa
to: cloudy
No, that will always fail. By the time the condition is evaluated, the trigger state has already changed. So this will trigger on “rainy”, and then check if it is “sunny” or “cloudy”, which it isn’t, because it is “rainy”.
If you want to check if it’s going from “sunny” or “cloudy” to “rainy” or “snowy”, add
from:
- "sunny"
- "cloudy"
into the trigger.
If that doesn’t solve it, then rather than going round in circles, can you explain what it is you’re trying to achieve?
Yeah sorry. I’m trying to prepare an automation to make the roller shutters close automatically when the weather get worse.
Looking at the possible states of met.no integration, I saw that those that predict bad weather are different. For this reason I simply wanted to make an automation that would make sure that any state that could foresee rain, would trigger the automation to lower the shutters.
At the moment, just for try, i set for action a simple notification to my smartphone.
- id: '1620898331665'
alias: shutters down
description: ''
trigger:
- platform: state
entity_id: weather.home
from: sunny,clear-night,cloudy,fog,partlycloudy,windy,windy-variant
condition:
action:
- service: notify.mobile_app_sm_g960f
data:
title: shutters down
mode: single
Does this works? With this automation, if the weather change to “rainy”, does the trigger work?
I don’t know where you’re getting the comma-separated list syntax from for the from: statement — I’ve never seen that and don’t believe it will work.
If you format the list as shown above, like this:
from:
- "sunny"
- "clear-night"
and so on, it will trigger when the state changes from anything in that list to anything. So a change from “windy” to “sunny” will trigger it, which is not what you want.
I think you want:
from:
- "sunny"
- "clear-night"
- (all other states for which you want the shutters open)
to:
- "rainy"
- "snowy"
- (all other states for which you want the shutters closed)
Speaking for myself, that seems a very complex trigger when you could check it every minute with a single line that won’t be susceptible to state term changes in the future and then you can handle the “to” states in the condition. But if it work for you then that’s all that really matters
I still don’t think you’re understanding fully, from what you’ve written — although the automation trigger you’ve written probably does what you want it to .
The trigger will work if the state changesfromany of the states listed under from:toany of the states listed under to:. Any other situation will not trigger the automation.
There are multiple ways to skin this cat, and what’s been proposed is 100% legitimate. So long as the state names stay consistent from both the integration and the weather data then you’re just fine doing what was proposed. For me, I try not to rely on static values too much just in case (and maybe I’m just paranoid), so I might trigger it every minute so I don’t have to have so many values in multiple locations or worry about making sure I took into accounting for all the “to” and “from” and just worry about what the current state is now:
trigger:
- platform: time_pattern
minutes: /1
condition:
- condition: state
entity_id: sensor.openweathermap_condition
state: sunny
- condition: or
conditions:
- condition: state
entity_id: sensor.openweathermap_condition
state: cloudy
I don’t know if you can do this, and if you can then awesome, but I’ve not implemented the multiple to/from entries like what was proposed, so this may or may not work: