I have prepared two automations to operate the air purifier. I have tested and both work as expected. My knowledge is unfortunately too small and, despite my efforts, it was not possible to create one from the two. Perhaps this is not possible at all. Please suggest if this can be done and how. Thank you. I will learn something from the best
Stop there, then. Why are you trying to combine them?
Looks like some messy logic though. Your first one:
triggers when your daytime or nighttime binaries change in either direction
then, if it’s between 0700 and 2200 or your daytime binary changed:
turns on the led
turns on the buzzer
if the particulates are:
high, turns the fan to auto
medium, turns the fan to silent
low, turns the fan off
if it’s between 2200 and 0700 or your nighttime binary changed
turns off the led and buzzer
sets silent mode
What’s the point of the two binary sensors in combination with the times? Wouldn’t a single binary on for day, off for night work? A Schedule helper could do that and can be set up with the UI.
@Troon they’re turning the first automation on and off from the second automation, which isn’t great. Otherwise, I’d agree that multiple, smaller automations are better.
@3jam3 you can put the action of the first in a script and rather call it that way if your goal is to minimise duplication.
As Troon touches on, you just need the one trigger in the first automation. Instead of testing for the trigger IDs, just test the binary sensor’s state.
I believe it would. I thought about this but was not sure if the time helper would trigger the needed option at, say, 7:00 a.m. Am I to understand that my fears are wrong and that it will trigger?
@Troon I did what you suggested. Indeed, it is simpler and more compact. It works. By the way, I used the schedule helper for other day/night automations and learned something new. Thanks. @parautenbach@Troon Now give me a hint whether I should integrate both automations or leave them as two separate ones. Because you have different opinions, guys
I don’t think there’s a hard line. I definitely have some large, combined automations, but that’s usually where I have very complex conditions I don’t want to duplicate, all just to decide (e.g.) to automatically open some door and turn on a light.
The problem often comes in when automations intersect. For example, if another automation will affect the same said light at the same time. You can get strange behaviours.
My general guidance towards smaller but multiple automations is that it tends to be easier to maintain, just like how one should write smaller, purposeful functions when programming.
For automations that either turn something on or off, I’d have it as one and use some templating.
In your case, roughly speaking, to combine the two, you need all the triggers together, as well as all the conditions. When trigger x fires, the conditions for x will already be true, but you want to then check conditions y are protecting you. Vise versa for when trigger y fires. Because, if I read your automations correctly, it’s all just about turning on or off the purifier, so a single automation might be OK. You’ll need to try it an see what you fancy.
Thanks for the clarification. I will rethink the matter.
I will ask one more thing. How do you make the selection conditions periodically checked? I have the impression that switching does not always happen according to the set ranges.
You can add a numeric state trigger too. Just be aware that it only triggers once the threshold is crossed. If, for example, the condition would be already true (the state is already within your parameters) at HA startup, the trigger won’t fire. For that case, also add a home assistant start trigger.
I’ve made a helper but I’m stuck. The helper does not have an entity ID and in Preview there is this message: Sensor None has device class 'pm25', state class 'measurement' unit 'µg/m³' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'medium' (<class 'str'>). What do I do now?
This is what the final and working version of my automation looks like. It switches modes as expected. Please comment, as there are probably some errors or inconsistencies in it.