Preventing a device's state change if a script is running

I use the Ubiquiti component for presence detection for two mobile phones and the main TV (all are connected over WiFi). My system works well and the alarm, automation rules etc work as I expect when everyone leaves and arrives home.

I now want to include some rules which will turn the TV on when we are out of town - simulating activity. A raspberry pi and HDMI-CEC commands have made this possible and I have a script which turns the TV on and changed the channel to live TV.

The problem I have is that as soon as the TV turns on the Ubiquiti component tells HASS that the device is ‘HOME’. This sets off a load of rules which disable the alarm etc etc.

One way of working around this is to check if my script is running, but I would need to do this in every rule that needs it. This seems complex and liable to break in the future.

Is there a way to add a condition to the state update event of the TV itself? For example, only set the state to HOME if a specific script is not running.

Not sure I understand how your TV fits into Away?

To determine if the house is in home or away mode I use the state of three devices. Two phones and the TV. With the TV off and the two phones out of range the alarm is set etc.

The TV coming on causes it to connect to my wifi. The Ubiquiti component reports this to HASS. Any device being home means the home group is marked as home.

Can you not just remove the TV from the device tracker? That seems a more straight-forward way to accomplish your goals.???

I agree, can you not find a better method to determine if your house is empty or not. The TV included with two MOBILE phones in determining this, is the issue and there is probably a much easier fix.

I’d rather not change what is:

  • Currently work fine

  • Fits my lifestyle

Is there anyway to perhaps filter the state of updates coming from a component and say suppress them. Like an automation rule than can trigger on any state change but programatically suppress further events?

That way I could trigger on state changes have a condition for the state of a script, then in the action set the state to AWAY and suppress any further events being generated.

Could I do this with a template on the components and in the template check whether my tv activity script it running? This feels like the solution i’m after.

This seems related:

So to answer my own question on this the best way to do this is to create a templated binary sensor.
The template consumes the states of the other devices and performs the more complex boolean logic.
This sensor is then uses to determine if the alarm etc is required

Another idea is to turn off the automation that changes home / not_home mode at the begging of the simulate script and turn it back on at the end of the script. A small automation might be added for when you return while the home is simulating activity.