I have 13 booleans named foobarsone1aktiv to foobarsone13aktiv. (Yes, it does mean Foobar Zone 13 Active). They are turned on when Foobar starts on the multizone server. While they are on, it means that Foobar is playing online radio in that zone, and scrape sensors should check every ten seconds if the playback info sent by the radio station has changed (for name of the song, artist, program and so on) and send the info to a webpage I have. Everything is working except for the starting and stopping of the ten second automation. I really don’t want 13 automations checking every ten seconds all the time, both because I fear it may bog down the system and because it throws errors in the log since the scrape sensor is disabled as long Foobar isn’t running, to avoid loops of trying to connect to something that isn’t there.
So what would be the way to do this? Do I need a second automation that starts the “every ten seconds” automation? I do not want to use enabling and disabling of automations, that’s prone to errors in my experience, booleans are much more reliable.
I could of course have them all running constantly and use the boolean as a condition, but I assume not running at all is better.
Thanks, but you misunderstand. I want to stop and start the running of them, I know about the time pattern trigger. That’s what I use to run it every ten seconds.
It’s hard to understand these details of what you have and want, but if I got it right, you could just add a condition to check the boolean. So that every 10 seconds the automations would run, but only if the boolean is true.
There are ways that I do similar things, but it’s complicated… The less complicated way is to just create an automation that turns on and off the 13 automations.
Set the trigger to be the state of the input boolean turning on. Put a repeat until in your actions with a delay of 10s until the state is off.
Maybe you can template the action to have it respond to 13 different triggers if you set the automation mode to parallel & use choose, but 13 separate automations would be more manageable if you want to disable specific zones.
@Fanful Thanks! So running 13 automations every 10 seconds and just stopping because of the condition doesn’t bog down a Pi 5 system? If it doesn’t I can simply do that, yeah.
@petro Of course it had to be complicated. Story of my life. Anyway, if the automations doesn’t bog down the system, I will do the boolean condition.
Edit, crossposting: @ShadowFist I will try that first, thanks!
I just don’t like disabling and enabling automations, I have had a few “accidents” when Hass has restarted for some reason, so they didn’t turn off or on as they should. And I prefer to have as little as possible running constantly. But if the code I put in with the run until is correct, I have what I need.
No, that doesn’t look quite right. Why are you targeting the automation in your last action?
Also, if you’re using individual automations per zone, mode should be set back to single to ensure you don’t end up with multiple instances of the same automation running.
Was just heading to bed so can’t really reply properly until tomorrow. Go through the automation, apply the changes & test.
I’ll check back on you tomorrow
Edit: put the update entity inside the sequence too. Missed that
The weird thing is that it doesn’t update the Scrape sensor. Suddenly it doesn’t update even if I do it manually. It only updates when Foobar starts, not during playback. I have to continue looking at that tomorrow. I couldn’t sleep because it didn’t work, and it was an Idiot error, so never mind…
So what I’d do is a template entity that sets your polling frequency. And you’d use that in all your automations.
template:
- triggers:
- trigger: state
entity_id: ... # Whatever you want to use to turn on/off the polling.
- trigger: time
at: sensor.polling_frequency
conditions:
- condition: state
entity_id: ... # whatever you need to make sure is on
state: 'on'
sensor:
- name: Polling Frequency
unique_id: 6b23d9b4-367f-4b05-9a4f-56218e8d8d3f
device_class: timestamp
state: "{{ now() + timedelta(seconds=10) }}"
It’s complex, however it’s extremely robust and all you need to do is manage that template entities triggers.
This process will:
Start exactly when you turn something on.
Exactly 10 seconds after it turns on, it will poll.
No crazy automations, only a somewhat crazy template.
Survive restarts if you add a restart HA trigger. Probably should also add a template reloaded trigger as well.
There are more things you can do to ensure the polling frequency is always exactly 10 seconds through restarts and reloading, but it’s probably not worth the pain.
@petro I’m a bit confused, sorry. I didn’t find how to create a template entity. Is this something I should put in the config.yaml, one of the different kinds of template helpers, and in that case which one, or something else that I just don’t know about?
Thank you! So I need one for each zone in the audio system, or just the one? Because if I add a trigger: state with foobarsone7aktiv as the trigger to the code in config.yaml, it would mean that I need one per zone in the audio system. I can’t have all zones starting the poll because one is active, that would create the same problem. Or can I use some variant like foobarsone{{ trigger_id }}aktiv in this?