Smart toggle switch for device (using a delayed network ping to detect power on / off)

I think you might find the updated code in the first post quite useful. You can adjust the timer to how long the tv takes to connect to the network and it doesn’t use automation.yaml anymore.

Thanks I will try it.

Quick question:do you experience your tv turning off by itself whilst pinging your samsung tv from HA ?

My Samsung tv always responds to pings while it is on. I haven’t noticed it showing as off in home assistant when it is actually on.

My tv will eventually turn itself off, if it is not used for several hours. It’s a power saving feature. I think there is an option on the tv to disable this.

Does that answer your question? If not ask again :slight_smile:

I think you will find the new code much better.

I think it does answer my question will look into the power saving feature on my tv.

Does your code remember that state of the tv if you restarted HA ?

If you restart HA it will pick up the power state again by pinging the TV again, it may take 2 seconds to update.

You’d have to add additional code to add this feature, and I think it is not necessary, because you shouldn’t restart your server frequently and it gets the power state again relatively quickly.

1 Like

Can you give me an example how to use it in automations? I need it as i am really getting crazy to automate some routines with my TV. I’ll appreciate this…

Works like a charm thanks for this, I have it implemented in my good night script and alarm set automation’s to turn off if state in “on”.

Thanks for this

1 Like

Will you share your automations for helping me to understand better how HASS works? I am really at first steps…
Thanks in advance.

Feel free to explore my repo for ideas of how to use.

if you need help message me I’d be happy to help


I see you use the Honeywell Xiaomi smoke detectors. Mine didn’t come with the battery so i haven’t set mine up yet. Question: If it goes off for burnt toast can you disable/silence the sirens for 15 minutes or something like that?

Yeah pretty much the same as a standard smoke detector you press the button on the unit to silence it.
Mine didn’t ship with the batteries either

This worked like a charm! Thank you very much!

1 Like

After reading the complete code, this should be the best way for me to realize it. In addition, I can detect the online status of the device through Ping. Unfortunately, the latest version can no longer use this code, and no one can create a blueprint.

I have a projector. I only need to press the on / off physical button once to turn it on, but I need to press the on / off physical button twice to turn it off.