I’d like to create a rule when the 3 hours weather forecast changes to state rain, that the blind will close automatically.
I just found out, that for rain openweathermap uses a lot of different state types (e.g. like low rain, heavy rain etc.) I just want to activate the rule as soon as the word “rain” has been found in the state update.
Is it possible to configure multiple states? can I do this with a semicolon at the state? Or do I have to use multiple “But only if” conditions? what happens if I add a 2nd one, are the 2 conditions then combined with “OR” or “AND” operators?
You can configure multiple triggers with specific states as one simple solution. All trigger are OR combinations so you can have: if this item changes to “light rain” OR if this item changes to “heavy rain”, but each of those would be a separate trigger.
You can also use a condition, but conditions are AND combinations, so you would have to use a script action on the condition that reads the item state and checks for the string rain in the state. This is a simple 1 or 2 lines in any of the script languages (and can even be done fairly easily in blockly if you prefer the low code option).
Just a hint: it’s much easier for people to read code in posts if you use “code fences” to help format it. You can either do it by using the button in the bar above the text area or just do it manually:
```
code goes here
```
I don’t know all the details of your weather setup, but you might get better luck using the Item “changed” trigger instead of the Item “updated” trigger.
Ok, wow, when you said there were a lot, you meant it…
There’s no reason you shouldn’t be able to get this to work the way you’re going, but with that many different options, moving the logic of testing the state to a script action is, as I said above, also a valid plan.
Again, this can be done in a blockly script relatively easily. You just need to make a list variable of the different state values:
(you can add more values to the list by clicking on the blue gear icon and dragging more item blocks into the list block structure).
Then you just do a simple test to see if the new state that triggered the rule is one of the strings in the list:
Inside the do block you can add as many send command blocks as you like to close your blinds or anything else you might also want to trigger as your automations grow more detailed.
No, both the changed TO and changed FROM parameters are optional. So you can just set the changed TO without having to worry about what the previous state was the same way you have with updated.
In this case changed is probably the better option anyway because that doesn’t depend on whether the item is getting updated or receiving a command. The event will trigger no matter what causes the value to change but will only trigger if the value does change.
For example if your forecast gets polled every 15 minutes, and updates the rain item to one of the rain values, which causes that item to change from a non-rain value, that will trigger an updated event and then trigger a changed event. If the next poll 15 minutes later sends an update to the rain item which is the same, you will get an other updated event (when you don’t really need to run the rule because it just ran last time) but you will not get a changed event (because the item state is already the same as the updated value).