Trying to make an automation to check if an item is already turned on

I have a working HA setup…and it has been running for a few years.

Core  2024.4.4
Supervisor  2024.04.0
Operating System 12.2
Frontend 20240404.2

In our media room, there is a lot of equipment that has to be powered on, input set etc. Currently partially using HA to call the Harmony Hub to do that automation, and just add a few items in the HA script.

I need to get away from Harmony, since Logitech stopped supporting it…and eventually it will die altogether.

The advantage of the Harmony system is it remembers the status of devices…so it doesn’t turn the receiver off when all you want to do is change inputs.

I am trying to take advantage of HA capabilities so it will not only remember what it turned on or off…but also (using ping) check the status if a device is already on or off.

Here is my first failure…this is in my scripts.yaml that is called by configuration.,yaml

theater_mode_off:
  alias: Everything Off
  sequence:
  - service: script.turn_off
    target:
      entity_id: script.projector_power_off
  - service: switch.turn_off
    target:
      entity_id: switch.denon_power
  - service: switch.turn_off
    target:
      entity_id: switch.dvdo_power
  - service_template: >
        {% if is_state('binary_sensor.192_168_11_15', 'on') %}
           script.pioneer_rec_poweroff
  - service: remote.send_command
    target:
      entity_id: remote.hub
    data:
      num_repeats: 1
      delay_secs: 0.4
      hold_secs: 0
      command: PowerOff
      device: 40278461

#etc...

and

pioneer_rec_poweroff:
   alias: ReceiveOFF
   sequence:
   - service: remote.send_command
     target:
       entity_id: remote.hub
     data:
       num_repeats: 1
       delay_secs: 0.4
       hold_secs: 0
       command: PowerOff
       device: 40278468	

the implemenation with the ping is obviously wrong…but I don’t understand what I am doing…this is the transition…once it is working with these Harmony codes…then I can change it to use an IP 2 IR device and send the hex codes.

Am I putting this in the wrong location…ie should it be a blueprint instead (and no idea what those are either)

The script worked until I started fixing it with the ping check. I would like it to set boolean flags so that the power status of items was logged so other scripts can check…only a couple of items will work with the ping command.

If someone could just point me in the right direction, it would be appreciated.

Thanks.
Mic

how to do this best varies from device to device. in this case it’s your pioneer amp? it’d be helpful to get more information about that device. how is it integrated into home assistant? can you show what entities it has, what states and attributes those entities support?

The trouble with IR and RF remotes is that HA has no knowledge of the devices being controlled - the only thing that is integrated is the remote itself. Presumably you’re replacing the Harmony hub with some other IR/RF device?

I have no knowledge of the Harmony hub - I’ve only used Broadlink, which I suspect is much less sophisticated - but with that I had a set of toggle helpers to represent the on/off state of the devices in automations etc. Even then, they were only assumed states.

If the devices were on wi-fi I used to ping them using the Ping (IMCP) integration, which gives you a simple binary sensor - much easier to use in automations and scripts.

scripts.yaml is the right place for a script - though I would urge you to use the UI editor if you’re not sure about anything. It will steer you past many mistakes and give a clear error if it can’t. It also allows you to look at the yaml relatively safely.

one thing to note… harmony hub does not track if the device is on. it tracks only if it thinks the device is on. it gets no feedback from the devices. so @youbecha, if you’re looking to replace harmony, you don’t actually need to do the ping/verify. you could do just what harmony does and maintain internal expected state…

Is that true in all cases? For IR obviously it makes sense, but many devices (like Roku) are controlled by network APIs from the Harmony Hub so I believe feedback is being provided in that case. The Harmony App will complain that it has better control through the API if you set a Roku up via IR (Which can have its advantages).

No, but this is the first time you’re mentioning a device which also happens to have API support.

Personally, I’d make the most of the Logitech database still being available and learn all the discrete commands that I can. Scripts and/or scenes will take care of making sure your devices don’t get out of sync

Fair enough, I guess I’m just pointing out that the Harmony Hub isn’t just a traditional IR remote and therefore only one way.

We can hope that when they eventually pull the plug, they will publish their database as open source. Who knows. I know I’ll miss it, but not as much as say 5 years ago. I’ve mostly eliminated IR controls.

You’re not wrong, but even as a dumb universal remote, it can be used to almost guarantee device states.

Discrete commands were a godsend back in the day when Logitech remotes didn’t come with a hub.
There’s no reason not to leverage the fact you can send the same set of commands a dozen times if you need to guarantee its delivery.

It worked solidly for many years for Logitech and it’s what earned them their reputation. No need to reinvent the wheel while you still have access to their database.

1 Like

Yep, I still have my hardware for flashing remotes back from the JP1 days.

1 Like

Harmony Hub remembers the status it creates…so you punch ‘watch bluray’ it does the sequence of events you set up to watch bluray. After you are done with that you punch ‘watch roku’ and it remembers that it already turned the receiver and TV on…it just needs to change input on the receiver, and it turnes off the bluray device…finally when you are done altogether, that ‘watch roku’ button is now the on/off, so you punch it again and the Harmony completely shuts everything back off.

As far as my receiver goes…if it is powered on, it responds to ping…if it is powered off , it does not.

I am simply trying to incorporate the ping check into a script, so if it responds to the ping, then it is already on…otherwise sending the power IR signal would shut it down again…most devices only have one power button over IR…so it just toggles the power status.

This is a script question.

Mic

Just be aware that the ping is a proxy for the receiver power state, in other words it has failure modes that may make the receiver appear to be off when it actually is just unreachable by the home assistant server. That said, the likelihood is slim you’ll run into those “corner cases”, but eventually you will :slight_smile: It’s always good to consider if those cases will result in a slight inconvenience or a real problem. In this case you’re probably good.

As pointed out earlier, an advantage of the Harmony and other IR controllers is that although physical remotes typically only have a power toggle, many devices actually have discrete on/off commands that can be used in the macro to ensure the state as long as the IR signal is received.

The reasons I need to move away from the harmony hub…

-15 total devices limit
-device is EOL
-unknown how long the servers will operate
-can only program the automations etc using a mobile device app connected to harmony server
-mine will no longer learn IR codes
-IR codes not being updated on database.
-you are not allowed to chose when in the automation certain devices are triggered
–for example, you have a wifi switch to power on/off devices that do not have a remote controllable power switch…those devices can ONLY go in one location on the automation
-often gets out of sync with receiver power

Mic

True, but even if you reach that limit, you can trick the remote into learning commands for lesser used devices, using an existing device.

Sadly true.

No. You can install My Harmony software on your PC.

Sounds like your remote has been software blocked by Logitech if you can’t learn IR either from an existing remote or via software.

Not quite. I can see last year’s LG OLED models there. This year’s models have just been released, so I’m sure they’ll show up too.

I’m pretty sure you can reorder the startup sequence, add a startup delay in the device settings, as well as a generic delay in the activity settings.

Which is why it’s a good idea to use discrete commands and to make sure HDMI CEC is disabled if you’re using one of these remotes.

I am waiting for some script advice.

Here’s some:

I don’t think this command is correct anymore.

  - service_template: >
        {% if is_state('binary_sensor.192_168_11_15', 'on') %}
           script.pioneer_rec_poweroff

service_template has been deprecated.

You can use service directly now Service calls - Home Assistant (home-assistant.io)

But either way your automation will generate an error when the Jinja if statement evaluates as false as you don’t provide a string for the false case, in which it will just be

- service: 

with nothing to call.

I would add if/then logic inside the automation, not with a template. Easily done in the automation editor these days.