I am trying to setup a template sensor that will determine if the shower is in use. I plan to use this combined with my Bayesian sensor for measuring if the bathroom is occupied or not.
I have a humidity sensor in the bathroom as well as one in the shower itself. What I plan to do is measure the difference between these two points. If the humidity in the shower is greater by say 10% than the rest of the room, the shower is likely in use.
I think a template sensor is likely the best way to do this but I am not sure how to do it. I havenāt done any āfunction-yā stuff with template sensors, just reformatting states. Any assistance anyone could provide would be great as I am not even sure how to begin.
Since this is a dual sensor Iām guessing the main state is temperature, not humidity. Double check the units too, you might have to do a type cast to be able to compare values from two different types of sensors. I donāt think the % sign should be there in the template sensor either but that depends on the types used.
Here is a slightly modified version of the code. The issue was I needed to pipe the first sensorās state into a float. I was mixing it with a string.
{% if states('sensor.temperatureandhumidity_13_0') == states('states.sensor.multisensor_233_2')|float +10 %}
This is only true if they are equal, as what I was proposing in my previous deleted post.
ā(sensor 1 = 10 and sensor 2 =10) = trueā
ā(sensor 1 = 5 and sensor 2 =10) = falseā
ā(sensor 1 = 10 and sensor 2 =5) = falseā
The sensors (most likely) return float values and you try to add an integer (10) before the comparison. Try adding 10.0 or type cast the sensor value to int before adding.
This works for me in the template engine, I havenāt tried adding it to my files.