Scripts for logitech harmony replacement

Like many harmony users, i am preparing for the day that my latest harmony remote or tge hub conk out.

I have a programmable universal remote that i can use with a esp32 + ir receiver to capture the codes sent and then have scripts to change those into the correct ir code for that activity. My sonoff ir blaster will do the rest.

The complications i am struggling with are around the following:

  1. If an activity uses more than one piece of hardware, such as the tv, a roku box and the speaker system, harmony is smart enough to recognise you have pressed the activity button more than once and scroll through each device on/off action for each press until everything is started correctly. This allows for unexpected initial status for any device. I am trying to work out if this logic can be easily coded and reusable for x numbers of devices. So i could pass in 2 or 3 hardware device names and then call the correct on/off actions for each device. If the on/off actions were via an On script and Off script for devices, how could i code the initial algorithm for the attempts at turning devices on and off to complwte the start activity?

  2. I would also need to be able to mimic individual remote buttons for a specific device rather than a universal activity e.g. i may need to change general tv settings such as network details and this is outside of activities such as Watch Netflix so would want my universal remote to act like the tv remote only. I know this one is a little vague but i guess i would need text helpers to hold current activity and current device, if one is selected. The latter would have priority if populated i guess? And be set to blank if an activity button is pressed again? Hoping someone has done this type of stuff before me.

Esphome for ir receiver and universal buttons:

esphome:
  name: irreceiver
  friendly_name: IRReceiver

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:
  level: VERBOSE

# Enable Home Assistant API
api:
  encryption:
    key: !secret irreceiver_api_key 

ota:
  password: !secret irreceiver_ota_password

wifi:
  networks:
  - ssid: !secret wholehome_wifi_ssid
    password: !secret wholehome_wifi_password
  - ssid: !secret wifi_ssid
    password: !secret wifi_password
  - ssid: !secret garden_wifi_ssid
    password: !secret garden_wifi_password

  manual_ip:
    static_ip: !secret irreceiver_ip   
    gateway: !secret wifi_gateway
    dns1: !secret wifi_dns
    subnet: !secret wifi_subnet    

# Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Irreceiver Fallback Hotspot"
    password: !secret irreceiver_wifi_ap_password

captive_portal:

remote_receiver:
  pin:
    number: GPIO14
    inverted: True
  dump: pioneer    

binary_sensor:
  - platform: remote_receiver
    name: "HomeApp TV"
    pioneer:
      rc_code_1: !secret universal1_homeapp_tv
  - platform: remote_receiver
    name: "Mute TV"
    pioneer:
      rc_code_1: !secret universal1_mute_tv
  - platform: remote_receiver
    name: "Power TV"
    pioneer:
      rc_code_1: !secret universal1_power_tv
  - platform: remote_receiver
    name: "1 TV"
    pioneer:
      rc_code_1: !secret universal1_1_tv
  - platform: remote_receiver
    name: "2 TV"
    pioneer:
      rc_code_1: !secret universal1_2_tv
  - platform: remote_receiver
    name: "3 TV"
    pioneer:
      rc_code_1: !secret universal1_3_tv
  - platform: remote_receiver
    name: "4 TV"
    pioneer:
      rc_code_1: !secret universal1_4_tv
  - platform: remote_receiver
    name: "5 TV"
    pioneer:
      rc_code_1: !secret universal1_5_tv
  - platform: remote_receiver
    name: "6 TV"
    pioneer:
      rc_code_1: !secret universal1_6_tv
  - platform: remote_receiver
    name: "7 TV"
    pioneer:
      rc_code_1: !secret universal1_7_tv
  - platform: remote_receiver
    name: "8 TV"
    pioneer:
      rc_code_1: !secret universal1_8_tv
  - platform: remote_receiver
    name: "9 TV"
    pioneer:
      rc_code_1: !secret universal1_9_tv
  - platform: remote_receiver
    name: "0 TV"
    pioneer:
      rc_code_1: !secret universal1_0_tv
  - platform: remote_receiver
    name: "ChList TV"
    pioneer:
      rc_code_1: !secret universal1_chlist_tv
  - platform: remote_receiver
    name: "Arrows TV"
    pioneer:
      rc_code_1: !secret universal1_arrows_tv
  - platform: remote_receiver
    name: "Menu TV"
    pioneer:
      rc_code_1: !secret universal1_menu_tv
  - platform: remote_receiver
    name: "Source TV"
    pioneer:
      rc_code_1: !secret universal1_source_tv
  - platform: remote_receiver
    name: "Up TV"
    pioneer:
      rc_code_1: !secret universal1_up_tv
  - platform: remote_receiver
    name: "Down TV"
    pioneer:
      rc_code_1: !secret universal1_down_tv
  - platform: remote_receiver
    name: "Left TV"
    pioneer:
      rc_code_1: !secret universal1_left_tv
  - platform: remote_receiver
    name: "Right TV"
    pioneer:
      rc_code_1: !secret universal1_right_tv
  - platform: remote_receiver
    name: "OK TV"
    pioneer:
      rc_code_1: !secret universal1_ok_tv
  - platform: remote_receiver
    name: "Exit TV"
    pioneer:
      rc_code_1: !secret universal1_exit_tv
  - platform: remote_receiver
    name: "Text TV"
    pioneer:
      rc_code_1: !secret universal1_text_tv
  - platform: remote_receiver
    name: "VolUp TV"
    pioneer:
      rc_code_1: !secret universal1_volup_tv
  - platform: remote_receiver
    name: "VolDown TV"
    pioneer:
      rc_code_1: !secret universal1_voldown_tv
  - platform: remote_receiver
    name: "YouTuTV TV"
    pioneer:
      rc_code_1: !secret universal1_yoututv_tv
  - platform: remote_receiver
    name: "NetTV TV"
    pioneer:
      rc_code_1: !secret universal1_nettv_tv
  - platform: remote_receiver
    name: "P ChUp TV"
    pioneer:
      rc_code_1: !secret universal1_pchup_tv
  - platform: remote_receiver
    name: "P ChDown TV"
    pioneer:
      rc_code_1: !secret universal1_pchdown_tv
  - platform: remote_receiver
    name: "Rewind TV"
    pioneer:
      rc_code_1: !secret universal1_rewind_tv
  - platform: remote_receiver
    name: "Pause Play TV"
    pioneer:
      rc_code_1: !secret universal1_pauseplay_tv
  - platform: remote_receiver
    name: "Prev TV"
    pioneer:
      rc_code_1: !secret universal1_prev_tv
  - platform: remote_receiver
    name: "Stop TV"
    pioneer:
      rc_code_1: !secret universal1_stop_tv
  - platform: remote_receiver
    name: "Next TV"
    pioneer:
      rc_code_1: !secret universal1_next_tv
  - platform: remote_receiver
    name: "Blue TV"
    pioneer:
      rc_code_1: !secret universal1_blue_tv
  - platform: remote_receiver
    name: "Green TV"
    pioneer:
      rc_code_1: !secret universal1_green_tv
  - platform: remote_receiver
    name: "Yellow TV"
    pioneer:
      rc_code_1: !secret universal1_yellow_tv
  - platform: remote_receiver
    name: "Blue TV"
    pioneer:
      rc_code_1: !secret universal1_blue_tv
  - platform: remote_receiver
    name: "Info LR TV"
    pioneer:
      rc_code_1: !secret universal1_infolr_tv
  - platform: remote_receiver
    name: "EPG 3D TV"
    pioneer:
      rc_code_1: !secret universal1_epg3d_tv
  - platform: remote_receiver
    name: "USB Fav TV"
    pioneer:
      rc_code_1: !secret universal1_usbfav_tv
  - platform: remote_receiver
    name: "PM Zoom TV"
    pioneer:
      rc_code_1: !secret universal1_pmzoom_tv
  - platform: remote_receiver
    name: "SM Setup TV"
    pioneer:
      rc_code_1: !secret universal1_smsetup_tv
  - platform: remote_receiver
    name: "Guide Sleep TV"
    pioneer:
      rc_code_1: !secret universal1_guidesleep_tv
  - platform: remote_receiver
    name: "HomeApp BOX"
    pioneer:
      rc_code_1: !secret universal1_homeapp_box
  - platform: remote_receiver
    name: "Mute BOX"
    pioneer:
      rc_code_1: !secret universal1_mute_box
  - platform: remote_receiver
    name: "Power BOX"
    pioneer:
      rc_code_1: !secret universal1_power_box
  - platform: remote_receiver
    name: "1 BOX"
    pioneer:
      rc_code_1: !secret universal1_1_box
  - platform: remote_receiver
    name: "2 BOX"
    pioneer:
      rc_code_1: !secret universal1_2_box
  - platform: remote_receiver
    name: "3 BOX"
    pioneer:
      rc_code_1: !secret universal1_3_box
  - platform: remote_receiver
    name: "4 BOX"
    pioneer:
      rc_code_1: !secret universal1_4_box
  - platform: remote_receiver
    name: "5 BOX"
    pioneer:
      rc_code_1: !secret universal1_5_box
  - platform: remote_receiver
    name: "6 BOX"
    pioneer:
      rc_code_1: !secret universal1_6_box
  - platform: remote_receiver
    name: "7 BOX"
    pioneer:
      rc_code_1: !secret universal1_7_box
  - platform: remote_receiver
    name: "8 BOX"
    pioneer:
      rc_code_1: !secret universal1_8_box
  - platform: remote_receiver
    name: "9 BOX"
    pioneer:
      rc_code_1: !secret universal1_9_box
  - platform: remote_receiver
    name: "0 BOX"
    pioneer:
      rc_code_1: !secret universal1_0_box
  - platform: remote_receiver
    name: "ChList BOX"
    pioneer:
      rc_code_1: !secret universal1_chlist_box
  - platform: remote_receiver
    name: "Arrows BOX"
    pioneer:
      rc_code_1: !secret universal1_arrows_box
  - platform: remote_receiver
    name: "Menu BOX"
    pioneer:
      rc_code_1: !secret universal1_menu_box
  - platform: remote_receiver
    name: "Source BOX"
    pioneer:
      rc_code_1: !secret universal1_source_box
  - platform: remote_receiver
    name: "Up BOX"
    pioneer:
      rc_code_1: !secret universal1_up_box
  - platform: remote_receiver
    name: "Down BOX"
    pioneer:
      rc_code_1: !secret universal1_down_box
  - platform: remote_receiver
    name: "Left BOX"
    pioneer:
      rc_code_1: !secret universal1_left_box
  - platform: remote_receiver
    name: "Right BOX"
    pioneer:
      rc_code_1: !secret universal1_right_box
  - platform: remote_receiver
    name: "OK BOX"
    pioneer:
      rc_code_1: !secret universal1_ok_box
  - platform: remote_receiver
    name: "Exit BOX"
    pioneer:
      rc_code_1: !secret universal1_exit_box
  - platform: remote_receiver
    name: "Text BOX"
    pioneer:
      rc_code_1: !secret universal1_text_box
  - platform: remote_receiver
    name: "VolUp BOX"
    pioneer:
      rc_code_1: !secret universal1_volup_box
  - platform: remote_receiver
    name: "VolDown BOX"
    pioneer:
      rc_code_1: !secret universal1_voldown_box
  - platform: remote_receiver
    name: "YouTuTV BOX"
    pioneer:
      rc_code_1: !secret universal1_yoututv_box
  - platform: remote_receiver
    name: "NetTV BOX"
    pioneer:
      rc_code_1: !secret universal1_nettv_box
  - platform: remote_receiver
    name: "P ChUp BOX"
    pioneer:
      rc_code_1: !secret universal1_pchup_box
  - platform: remote_receiver
    name: "P ChDown BOX"
    pioneer:
      rc_code_1: !secret universal1_pchdown_box
  - platform: remote_receiver
    name: "Rewind BOX"
    pioneer:
      rc_code_1: !secret universal1_rewind_box
  - platform: remote_receiver
    name: "Pause Play BOX"
    pioneer:
      rc_code_1: !secret universal1_pauseplay_box
  - platform: remote_receiver
    name: "Prev BOX"
    pioneer:
      rc_code_1: !secret universal1_prev_box
  - platform: remote_receiver
    name: "Stop BOX"
    pioneer:
      rc_code_1: !secret universal1_stop_box
  - platform: remote_receiver
    name: "Next BOX"
    pioneer:
      rc_code_1: !secret universal1_next_box
  - platform: remote_receiver
    name: "Blue BOX"
    pioneer:
      rc_code_1: !secret universal1_blue_box
  - platform: remote_receiver
    name: "Green BOX"
    pioneer:
      rc_code_1: !secret universal1_green_box
  - platform: remote_receiver
    name: "Yellow BOX"
    pioneer:
      rc_code_1: !secret universal1_yellow_box
  - platform: remote_receiver
    name: "Blue BOX"
    pioneer:
      rc_code_1: !secret universal1_blue_box
  - platform: remote_receiver
    name: "Info LR BOX"
    pioneer:
      rc_code_1: !secret universal1_infolr_box
  - platform: remote_receiver
    name: "EPG 3D BOX"
    pioneer:
      rc_code_1: !secret universal1_epg3d_box
  - platform: remote_receiver
    name: "USB Fav BOX"
    pioneer:
      rc_code_1: !secret universal1_usbfav_box
  - platform: remote_receiver
    name: "PM Zoom BOX"
    pioneer:
      rc_code_1: !secret universal1_pmzoom_box
  - platform: remote_receiver
    name: "SM Setup BOX"
    pioneer:
      rc_code_1: !secret universal1_smsetup_box
  - platform: remote_receiver
    name: "Guide Sleep BOX"
    pioneer:
      rc_code_1: !secret universal1_guidesleep_box
  - platform: remote_receiver
    name: "HomeApp Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_homeapp_subdvd
  - platform: remote_receiver
    name: "Mute Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_mute_subdvd
  - platform: remote_receiver
    name: "Power Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_power_subdvd
  - platform: remote_receiver
    name: "1 Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_1_subdvd
  - platform: remote_receiver
    name: "2 Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_2_subdvd
  - platform: remote_receiver
    name: "3 Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_3_subdvd
  - platform: remote_receiver
    name: "4 Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_4_subdvd
  - platform: remote_receiver
    name: "5 Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_5_subdvd
  - platform: remote_receiver
    name: "6 Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_6_subdvd
  - platform: remote_receiver
    name: "7 Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_7_subdvd
  - platform: remote_receiver
    name: "8 Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_8_subdvd
  - platform: remote_receiver
    name: "9 Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_9_subdvd
  - platform: remote_receiver
    name: "0 Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_0_subdvd
  - platform: remote_receiver
    name: "ChList Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_chlist_subdvd
  - platform: remote_receiver
    name: "Arrows Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_arrows_subdvd
  - platform: remote_receiver
    name: "Menu Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_menu_subdvd
  - platform: remote_receiver
    name: "Source Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_source_subdvd
  - platform: remote_receiver
    name: "Up Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_up_subdvd
  - platform: remote_receiver
    name: "Down Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_down_subdvd
  - platform: remote_receiver
    name: "Left Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_left_subdvd
  - platform: remote_receiver
    name: "Right Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_right_subdvd
  - platform: remote_receiver
    name: "OK Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_ok_subdvd
  - platform: remote_receiver
    name: "Exit Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_exit_subdvd
  - platform: remote_receiver
    name: "Text Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_text_subdvd
  - platform: remote_receiver
    name: "VolUp Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_volup_subdvd
  - platform: remote_receiver
    name: "VolDown Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_voldown_subdvd
  - platform: remote_receiver
    name: "YouTuTV Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_yoututv_subdvd
  - platform: remote_receiver
    name: "NetTV Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_nettv_subdvd
  - platform: remote_receiver
    name: "P ChUp Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_pchup_subdvd
  - platform: remote_receiver
    name: "P ChDown Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_pchdown_subdvd
  - platform: remote_receiver
    name: "Rewind Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_rewind_subdvd
  - platform: remote_receiver
    name: "Pause Play Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_pauseplay_subdvd
  - platform: remote_receiver
    name: "Prev Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_prev_subdvd
  - platform: remote_receiver
    name: "Stop Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_stop_subdvd
  - platform: remote_receiver
    name: "Next Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_next_subdvd
  - platform: remote_receiver
    name: "Blue Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_blue_subdvd
  - platform: remote_receiver
    name: "Green Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_green_subdvd
  - platform: remote_receiver
    name: "Yellow Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_yellow_subdvd
  - platform: remote_receiver
    name: "Blue Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_blue_subdvd
  - platform: remote_receiver
    name: "Info LR Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_infolr_subdvd
  - platform: remote_receiver
    name: "EPG 3D Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_epg3d_subdvd
  - platform: remote_receiver
    name: "USB Fav Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_usbfav_subdvd
  - platform: remote_receiver
    name: "PM Zoom Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_pmzoom_subdvd
  - platform: remote_receiver
    name: "SM Setup Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_smsetup_subdvd
  - platform: remote_receiver
    name: "Guide Sleep Sub DVD"
    pioneer:
      rc_code_1: !secret universal1_guidesleep_subdvd
  - platform: remote_receiver
    name: "Brightness Up Small"
    pioneer:
      rc_code_1: !secret universal2_brightness_up
  - platform: remote_receiver
    name: "Brightness Down Small"
    pioneer:
      rc_code_1: !secret universal2_brightness_down
  - platform: remote_receiver
    name: "Next Small"
    pioneer:
      rc_code_1: !secret universal2_next
  - platform: remote_receiver
    name: "Power Small"
    pioneer:
      rc_code_1: !secret universal2_power
  - platform: remote_receiver
    name: "Blue Column 1 Small"
    pioneer:
      rc_code_1: !secret universal2_bluecol_1
  - platform: remote_receiver
    name: "Blue Column 2 Small"
    pioneer:
      rc_code_1: !secret universal2_bluecol_2
  - platform: remote_receiver
    name: "Blue Column 3 Small"
    pioneer:
      rc_code_1: !secret universal2_bluecol_3
  - platform: remote_receiver
    name: "Blue Column 4 Small"
    pioneer:
      rc_code_1: !secret universal2_bluecol_4
  - platform: remote_receiver
    name: "Blue Column 5 Small"
    pioneer:
      rc_code_1: !secret universal2_bluecol_5
  - platform: remote_receiver
    name: "Green Column 1 Small"
    pioneer:
      rc_code_1: !secret universal2_greencol_1
  - platform: remote_receiver
    name: "Green Column 2 Small"
    pioneer:
      rc_code_1: !secret universal2_greencol_2
  - platform: remote_receiver
    name: "Green Column 3 Small"
    pioneer:
      rc_code_1: !secret universal2_greencol_3
  - platform: remote_receiver
    name: "Green Column 4 Small"
    pioneer:
      rc_code_1: !secret universal2_greencol_4
  - platform: remote_receiver
    name: "Green Column 5 Small"
    pioneer:
      rc_code_1: !secret universal2_greencol_5
  - platform: remote_receiver
    name: "Blue Column 1 Small"
    pioneer:
      rc_code_1: !secret universal2_bluecol_1
  - platform: remote_receiver
    name: "Blue Column 2 Small"
    pioneer:
      rc_code_1: !secret universal2_bluecol_2
  - platform: remote_receiver
    name: "Blue Column 3 Small"
    pioneer:
      rc_code_1: !secret universal2_bluecol_3
  - platform: remote_receiver
    name: "Blue Column 4 Small"
    pioneer:
      rc_code_1: !secret universal2_bluecol_4
  - platform: remote_receiver
    name: "Blue Column 5 Small"
    pioneer:
      rc_code_1: !secret universal2_bluecol_5
  - platform: remote_receiver
    name: "White Column 1 Small"
    pioneer:
      rc_code_1: !secret universal2_whitecol_1
  - platform: remote_receiver
    name: "White Column 2 Small"
    pioneer:
      rc_code_1: !secret universal2_whitecol_2
  - platform: remote_receiver
    name: "White Column 3 Small"
    pioneer:
      rc_code_1: !secret universal2_whitecol_3
  - platform: remote_receiver
    name: "White Column 4 Small"
    pioneer:
      rc_code_1: !secret universal2_whitecol_4
  - platform: remote_receiver
    name: "White Column 5 Small"
    pioneer:
      rc_code_1: !secret universal2_whitecol_5
  - platform: remote_receiver
    name: "Blue Up Small"
    pioneer:
      rc_code_1: !secret universal2_blue_up
  - platform: remote_receiver
    name: "Blue Down Small"
    pioneer:
      rc_code_1: !secret universal2_blue_down
  - platform: remote_receiver
    name: "Green Up Small"
    pioneer:
      rc_code_1: !secret universal2_green_up
  - platform: remote_receiver
    name: "Green Down Small"
    pioneer:
      rc_code_1: !secret universal2_green_down
  - platform: remote_receiver
    name: "Blue Up Small"
    pioneer:
      rc_code_1: !secret universal2_blue_up
  - platform: remote_receiver
    name: "Blue Down Small"
    pioneer:
      rc_code_1: !secret universal2_blue_down
  - platform: remote_receiver
    name: "Quick Small"
    pioneer:
      rc_code_1: !secret universal2_quick
  - platform: remote_receiver
    name: "Slow Small"
    pioneer:
      rc_code_1: !secret universal2_slow
  - platform: remote_receiver
    name: "Auto Small"
    pioneer:
      rc_code_1: !secret universal2_auto
  - platform: remote_receiver
    name: "Flash Small"
    pioneer:
      rc_code_1: !secret universal2_flash
  - platform: remote_receiver
    name: "Jump 3 Small"
    pioneer:
      rc_code_1: !secret universal2_jump3
  - platform: remote_receiver
    name: "Jump 7 Small"
    pioneer:
      rc_code_1: !secret universal2_jump7
  - platform: remote_receiver
    name: "Fade 3 Small"
    pioneer:
      rc_code_1: !secret universal2_fade3
  - platform: remote_receiver
    name: "Fade 7 Small"
    pioneer:
      rc_code_1: !secret universal2_fade7
  - platform: remote_receiver
    name: "DIY 1"
    pioneer:
      rc_code_1: !secret universal2_diy1
  - platform: remote_receiver
    name: "DIY 2"
    pioneer:
      rc_code_1: !secret universal2_diy2
  - platform: remote_receiver
    name: "DIY 3"
    pioneer:
      rc_code_1: !secret universal2_diy3
  - platform: remote_receiver
    name: "DIY 4"
    pioneer:
      rc_code_1: !secret universal2_diy4
  - platform: remote_receiver
    name: "DIY 5"
    pioneer:
      rc_code_1: !secret universal2_diy5
  - platform: remote_receiver
    name: "DIY 6"
    pioneer:
      rc_code_1: !secret universal2_diy6
#

I can’t answer your second point, but I have a tip for your first.

The way I would do it is exactly how the Harmony handles it - use dedicated commands as much as possible. By that I mean a single command to go to eg. HDMI2 instead of navigating the source menu, or sending PowerOn instead of PowerToggle. You should be able to learn these direct commands directly off your Harmony remote while it’s still operational.

That will at least allow you to replay the script from the beginning without causing devices to go out of sync, irrespective of what failed. You’d just call your last activity and whatever didn’t make it through the first time will (hopefully) make it on subsequent attempts.

Side note - any particular reason you’re storing your* remote codes in your secrets file?
*They’re universal codes, so might as well avoid the potential latency and add them directly in your yaml

@stain3565 i’m doing this as well for my harmony… i have a number of them so i know it’ll happen at some point!

i don’t know about the esplevel programming… i’m doing everything up at the scripts & automation & lovelace yaml level.

i thought i might take the liberty to share an element of my design that has really helped my implementation… i have scripts named:

script.{{ activity }}_{{ action }}

so for example: script.firetv_fastforward and script.dvd_fastforward

i have helper entities that are the current activity… then when i have a generic ui buttons, it does this:

service: script.{{ states(input_text.current_activity) }}_{{ button_pressed }}

this makes it much easier to build the actual remote ui and branch to different behaviors depending on what the current activity is.

hope this might be helpful to you. good luck!

1 Like

@ShadowFist Hi thanks for replying. The only reason for the secrets codes was i found it simpler to maintain and edit them. Maybe a false economy but having them in an uninterrupted list meant i could work with them better.

I will try out a few of the power commands on the harmony remote but i don’t think all of them do have distinct power on or power off commands. Will check.

@armedad Will take your code on board and see how i can integrate your ideas. Cheers

Cool post, I’m thinking about the dreaded point as well. Although my dependency of IR disappeared for several years, I’m finding it necessary again to use my 25 year old amplifier.
I don’t have the sonoff, I’m trialling a board made by @WaresMyHass which is well made https://community.home-assistant.io/t/ir-transmitter-long-range-hardware-suggestions/643055/27

OK, things progressing nicely but, as my devices do not have discrete power codes and I am having to work with power toggles, I still haven’t sussed out the logic for ensuring pressing my activity button over and over again will at some point ensure that all devices are in the powered on position.

The scenario is as follows:

Watching TV via settop box requires:

  1. TV powered on with input1 selected
  2. Soundbar on with TV input selected
  3. Settop box on

The selected inputs should not be an issue as I can attempt these whether power toggle turns on or off. If off, they simply will not change anything as the signals will not be received.

I know that there are 8 possible combinations (using binary logic) but my brain struggles with how this would work. I know the 1st action must be to power toggle all 3. If that turns everything on, I don’t need to press the Watching TV activity button again. However, one or more of these devices may have been on so it may take several key presses.

As there are 8 combinations after the initial power toggle for all, I have in my head the idea of using the concept of a 3 digit binary number and adding 1 to it on each press. The first digit will represent the TV, second the Soundbar and third the settop box.

If adding 1 changes the first digit, I need to power toggle the TV. If it also changes the second digit, then power the Soundbar and if the third changes, power the settop.

so starting at 000, adding 1 results in 001 which means just power the settop box. Add another 1 means 010 which means changes to 2nd and third digits so power both the Soundbar and settop box. etc

If I do accidentally miss when all are powered on, at some point the number will be 111 so I will need to reset to 000 at that point unless I allow it to move to 1000 and my logic actually works with just the last 3 digits.

It seems logical to me but I may be overthinking it and I would have no idea how to code this. I can capture pressing the Watch TV activity after a previous press but how I carry out the above logic when it happens, I have no idea how such a script would be coded.

Update: May have worked it out.

Input_number.power_toggle default 0 step by 1

if pressed activity another time:

Increment power_toggle   

If divisible by 1 (i.e. always!!), power toggle settop (I will use input_booleans to flag which need powering)
If divisible by 2, power toggle Soundbar
If divisible by 4, power toggle TV
If at 8, reset to 0

I thought I might need to reset the value when different key pressed but guess I don’t need to as this will move through all possibilities regardless of what value the input_number starts at.

before you go through all of that, are you positive your devices don’t have a ir “on” and ir “off” codes? most of my media devices have those… even if the remote it came with only have toggle.

since you are moving from harmony, look in the device codes for haromony and verify.

iff you need to do this, is your ir blaster super reliable? the issue with this method is that if it has flakiness (e.g. 25% of the time, the toggle code doesn’t take), then things get really really messy.

1 Like

+1 to @armedad’s post above. I’ve rarely seen a device without a discrete command in the Logitech database.

Worst case scenario is to check other models from the same manufacturer and you’ll find the missing discrete commands

this might be helpful to you if you do end up cycling through toggling for any devices that you can’t find a dedicated ‘on’ code:

the concept is pretty simple… just count, and each time figure out which binary digit changes from one number to the next. that’s digit “toggled” and so should that device.

alias: test cycle toggle
sequence:
  - repeat:
      count: 7
      sequence:
        - if:
            - condition: template
              value_template: "{{ ((repeat.index+1) % 2) | int !=  (repeat.index % 2) | int}}"
          then:
            - service: switch.toggle
              target:
                entity_id: switch.device1
        - if:
            - condition: template
              value_template: "{{ (((repeat.index+1) / 2) % 2) | int != (((repeat.index / 2 ) % 2) | int)}}"
          then:
            - service: switch.toggle
              target:
                entity_id: switch.device3
        - if:
            - condition: template
              value_template: "{{ ((((repeat.index+1) / 4) % 2) | int) != (((repeat.index / 4) % 2 ) | int )}}"
          then:
            - service: switch.toggle
              target:
                entity_id: switch.device3

As i delved deeper, i realised that some of my devices had other methods of carrying out commands.

Eg
Sony Bravia Tv - can use the Sony Bravia integration
Roku Premiere - can use the Roku ECP or Roku integration with remote.send

The Bravia method has a TVPower and PowerOff command. I could just ensure the PowerOff is run for any initial activity press followed by TVPower and that would do.

I will use discrete commands for ir calls if Harmony supports these but am trying to reduce IR signals where possible.

Currently, the only ir signals i need to send are for my Samsung Soundbar and my BT humax box. I am experimenting with auto power on the soundbar which should guarantee it turns on when the tv turns on.

yes, I have a few bravias. they are actually running android TV so you can also use the Android TV commands on them

also, bravia supports cec. I am able to wake my tv via my amp. your Roku might be able to wake the tv…

what is cec?

you might need to enable it. but it allows the tv to send commands to things like roku and vice versa. things like up/down/left/right, play, pause, you can send via the sony remote without telling sony what device you’ve got sitting on the hdmi port.

the reson why this is potentially beneficial in this scenario is because

  1. some of the direct commands to some devices aren’t great. e.g. the command to fire tv are super slow unless you drop to raw adb_commands. also if you have, say… a roku on hdmi1 and a blu-ray on hdmi2, you can send a fast-forward command to sony and it will turn around and send the right command to the right device.