I want to create my first automation. I read several examples, but there are too many variants. So perhaps if I understand the code for my needs it will clear things. Anyway, here’s what I’m looking for:
I have 4 shelly covers defined. For each entity there’s the attribute has_firmware_update which can be true or false.
So I want to define an automation to notify (notify.notify_hmtl5 for example) when each entity changes from false to true.
if the info is in an attribute, you have 2 options:
create a template binary sensor for each entity and extract its attribute, then create an automation that triggers on the template sensor’s state change
create an automation that triggers on time interval (e.g. every 5 min) with a condition that at least 1 of the sensors has attribute to true and then send a notification
I’d personally think the first one feel like more work to do, but it’ll be easier to handle / use, especially for a newb
the 2nd will require less work to set up, but more complex coding, which for a a newb could be a bit overwhelming
so first option:
you create a template binary sensor for each of your shelly covers:
Above allows you to have a single automation that gives you the name of the entity that has an update available.
For the 2nd option, well since you’re a newb I would not recommend diving into this just yet, but you can have a look at how I list which windows are forgotten opened when my car gets locked:
Glad it helped. Feel free to mark as Answer so others can see how you did it.
Triggers only work on state change, as in not on attribute change. You could use the original cover and remove the to: 'on' line, but then you’d also need to add conditions on the templates else it’ll send a notification each time anything changes in that sensor.
one notification per cover when has_firmware_update goes from "false" to "true"
[edit] Correction, you could trigger on an attribute.
Replace the trigger lines from:
- platform: state
entity_id:
- binary_sensor.shelly_cover_1_update_available
- binary_sensor.shelly_cover_2_update_available
- binary_sensor.shelly_cover_3_update_available
- binary_sensor.shelly_cover_4_update_available
to: 'on'