First of all, thank you to this great community. I have HA for 2 years and it is the first time I need to write a post (because all the information is there!)
My set up:
A synology running a docker container with HA and mainly tasmotized sonoffs
I have an electric valve that controls whether I use the hot water coming from the solar energy system or from the water heater. I control that with 2 relays of a sonoff 4CH Pro with tasmota
I have an automation that every time the temperature of the water in the solar system goes below 35 degrees it switches the relay to move the valve and use the boiler (and switches it off after 30 seconds) and if it goes above 35 it switches the other relay to move the valve in the other direction.
My 2 problems
I want to know when I am using the solar or the electric system in a given moment. I thought that I could create a new entity that would capture when each of the relays goes to ON but I do not know if this is possible (or even if it is a good idea)
The automation is triggered every time the sensor updates the temperature. How can I trigger the automation just when the temperature crosses 35 degrees in one or other direction?
For 2: In your automation trigger on sensor state change then use a condition section to test for your set temperature along with trigger.to_state and trigger.from_state to determine direction. The from_state is the previous trigger state and the to_state is the current state. So depending on which is larger you have direction.
Thanks for pointing me in the right direction. It took a while for me to learn about template sensors (first time I use it). It is not working so far. I created a binary sensor that captures when the other 2 entities are ON. It is not working so far. But actually, I want to capture the change to On in each of the entities and keep it like this until the other entity is On. Here is my code so far:
Want I want to capture is the last switch that turned ON.
It does not matter the current state or if they turn OFF. I have an automation that turns OFF 30 seconds after they are turned ON so most of the day they will be OFF. So I want to have a sensor to know which one was turned on last (that will determine whether I am using water coming from the Solar or boiler system).
When either switch changes state to on its name (object_id) is published to the topic sensor/placa_termo. The sensor is subscribed to this topic and so its state will indicate either placa or termo, whichever was the last one to turn on.
The sensor’s initial state will be unknown and will only change when one of the two switches turns on.
The switch’s name is published as a retained message. This means the MQTT Broker will store the payload. When Home Assistant restarts, the sensor will re-subscribe to sensor/placa_termo and get last stored message (either placa or termo).
It works fantastic! Thank you so much. May I use your brain for the second problem?
I want switch.placa and switch.termo to be triggered when the temperature goes above or below 35 degrees respectively. The problem is that the automation keep triggering every time the temperature sensor updates the temperature (and it is different to the previous one). This is the code of the automations that I have:
A Numeric State Trigger only triggers when the entity’s value crosses the threshold value. In your first automation, it will trigger when temperatura_placa crosses the threshold of 34. In other words, when it is equal to or less than 34 and only the first time it happens. After it crosses the threshold, any further decrease does not re-trigger the automation. The value of temperatura_placa has to first rise above 34, then fall below it to re-trigger the automation. That’s how a Numeric State Trigger works.
You were right (again). It took me a while to figure the issue.
It only triggers when it crosses the threshold. The issue is that it is hot water and when we do not use it is reduces the temperature progressively until it crosses again the threshold. When we open it again the hot water reaches the temperature sensor and triggers the automation. Not sure how to fix this but it is not a big deal.
Please mark my post (containing the MQTT Sensor example) with the Solution tag. Only you, the author of this topic, can do that. It will automatically place a check-mark next to the topic’s title, signaling to others that this topic has an accepted solution. It will also automatically place a link beneath your first post that leads to the solution. All of this helps others who may have a similar question and are looking for answers.