If device is home script

Hi,

I have setup HASS to track the on status of my TV and DVDplayer . If they are on, I receive an icon called DVD and TV home, which is great. I just need to be able to add a line in my script that says:

If DVD is not home turn on
If TV is not home turn on.

I’m at a loss on how to do this in homeassistant. I see alot of people do this with triggers and automations, however can I do this from a simple script with and if then statement?

How are you tracking the status of these devices? If you are using the media-player component, then you should be able to use the following in your automation:

service: media_player.turn_on
entity_id:<your TV>

I have the following to track the device

device_tracker:

  • platform: ping
    hosts:
    tv_family: 10.0.0.X
    dvd_family: 10.0.0.Y
    tbox_family: 10.0.0Z
    interval_seconds: 10

When the device comes online, it status changes to home - which is great. I just need a way to check its status in the scripts.

movieon:
sequence:
- service: wake_on_lan.send_magic_packet
data:
mac: 00:XX:XX:XX:XX:XX
#check if tv_family.home, if no, turn on TV
- service: script.tvon_

See the Condition documentation. It works the same for scripts (the last example on the Script page includes condition.)