I’m quite new in HA world as I started in may 2021.
I have a Pi where HA OS is running up to date. I am using ZigBee2MQTT and paired 18 devices (temperature/humidity, switches, TRV, motion sensors…).
I managed to create several automations using HA integration.
But now, I am facing a little pain in my a## as I can’t manage how to make what I want to work.
I am willing to trigger a switch using a template condition by comparing sensor 1 and sensor 2 like sensore 1 > sensor 2.
I know it may be very trivial for you but I am not a programmer and only start to understand what I am doing.
I used the developer tool to check the template and it is working. But I may forget something to make it work in an automation.
Could you please help me to understand what is missing ?
There is no error in HASS log…
When I click on execute, it is going as normal.
But when it is left on auto, it is just doing nothing even if i’d like it to !
If you start the automation “by hand” eg. in the template editor, the trigger will not be checked.
I wouldn’t use the device platform, this is the perfect use case for a numeric_state trigger. I’m not a fan of the device trigger, makes things more complicated than needed, imho.
You have to convert the entity’s state value to a numeric value using either int or float. If you don’t do that, it is comparing the two values as strings (text) which can produce unexpected results.
You should also be aware of how the trigger works (it’s a Numeric Device Trigger which is effectively the same as a Numeric State Trigger). It will trigger when the humidity increases from below 70 to above 70 and remains above 70 for at least 5 minutes. Once it triggers, it won’t trigger again until the humidity first decreases below 70 and then increases above it.
If you created the automation when the humidity was already above 70, the automation will not trigger. The humidity must first decrease below 70 and then increase above it to trigger the automation (or restart Home Assistant or reload automations).
Thanks a lot for your help ! it’s working now !
To test, I just had to restart the server. When it starts, the automation is launched.
Tried with > to verify it was not an artefact
To be clear, there was nothing wrong with the automation’s trigger. Changing it from a Numeric Device Trigger to a Numeric State Trigger reduces the number of lines of code but doesn’t change the behavior (two ways of creating the same kind of trigger).
Reducing the Numeric Trigger’s threshold value and then reloading automations serves to reset the trigger.
What was definitely incorrect was arithmetically comparing two state values without first converting them to numeric values.
Well thank you for your help ! I was not far from the goal but I would have missed this important part !
For me it is time to sleep ! I juste have to wish you a pleasant afternoon
If you wouldn’t mind, please mark the post from Taras as solution (the checkbox under his first post). Helps others to see the solution at first glance! Thanks!
And a pleasant afternoon to you, too from the balcony looking in the night sky.
Taras,
I don’t know if I can add another question in the same topic but it is related.
I was wondering if it was possible to make some kind of mathematic operations like :
Hello,
I intend to do something similar also to automate a VMC unit based on humidity of a bathroom, but I want that the trigger occurs based on value from two sensors. One is the humidity’s mean of last 2hr, and the other is the actual humidity.
I already created the statistics sensor to get humidity’s mean.
I’m using Triggers type - Template, and this is the code: