I have created a sensor based on the time an xbox is with an active user:
sensor:
- platform: history_stats
name: Xbox encendida hoxe Hugo
entity_id: binary_sensor.xxxxx
state: 'on'
type: time
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
so far so good, the sensor works correctly, it shows me the time it is on in hh:mm:ss format and in the developers section with a numerical value corresponding to the hours of use:
What is the time pattern trigger for? Since you don’t have a general condition set for the automation, when the time pattern trigger fires the actions will proceed no matter how long the XBox has been in use.
I have adapted the configuration of another post seen in the forum, from a ps4. Automate Time Limit on PS4
So I don’t know exactly what the time pattern is for, the intention is that the automation runs every, so often for if the user’s session is active again. should i remove it then?
There is no need to continually check how long it has been used for, because that’s what your above: 2 is for (though if you want it to fire when it is 2 hours, it should be above: 1, above 2 mans it won’t trigger until 3 hours). The only condition checks that the binary sensor is on.
OK, I have checked the post you mentioned and I can explain what is going on.
In that post - they are using a 5 minute trigger to run the automation, and then a condition to check the numeric state of the sensor.
They are doing this, because as a trigger - it only fires when the threshold has been crossed, and will not fire again until the number falls below the threshold and rises again. So basically - it’s to prevent someone turning the PS4 back on after the automation turned it off.
If it was me, and I was setting up the automation to turn off the games console with a grace time like in the post you linked to, I would be using a choose - so that if the binary sensor is on, and the sensor is above 2.04 then it switches off immediately with no grace warning. Because it has obviously been switched back on, and it’s the only way they will learn that rules are rules