I’m trying to track the cumulative state of a room but I’m struggling to trigger the state change from within an automation. There are similar threads but, i think, for slightly different use cases.
To better the control the melee of my family I want to be able to classify a room’s state as being either Active, Quiet or Silent. Active when the room is being used and triggering a motion sensor, Quiet when there is no movement but media players etc are still on, Silent after an extended Quiet duration and triggering a variety of services to turn off lights, music, TVs etc. maybe activating locks (no sure).
The state behavior is fairly well structured, so for example:
i) Active will can only go to Quiet (no motion for maybe 5 minutes)
ii) Quiet can go back to Active (new motion) or to Silent (no new activity for 30 mins say)
iii) Silent can go to Quiet but not directly to Active
There is also a security element to this; a Silent room should not detect motion without the internal door being unlocked first (taking the room to Quiet) and then to Active if motion is detected. Motion in a Silent room would trigger an alert.
I’ve managed to implement this using timers and Bayesian sensors, the concept works but its clumsy; using a combination of binary Bayesian sensors to simulate a 3 state enumeration is awkward.
I’d like to model this using a template sensor to create an enumerated room state sensor and then use automations triggered by state changes of sensors and devices in the room to step between the enumerated states. The template sensor is simpler than the Bayesian approach and the automation’s For condition could simplify the timer use.
But (and with growing sense that I’ve missed something obvious) I can’t see how I change the state of the template room state sensor from within an automation. Is it possible in HA?
I could do this with Node-Red and communicate the state change through an MQTT interface but I’d rather keep it within HA to allow more sophisticated use of entity states in the future.
Any thoughts…? Thank you.