IR Blaster to Turn On/Off Surround Sound Faster Based on Energy Current with Sonoff S31

Goal:
Have Home Assistant quickly turn on/off the surround sound after it noticed the TV turn on. To ensure that the surround sound is on/off, repeat the command with the IR blaster until the Sonoff S31 identifies the enegery current is at the correct level. I am willing to go a completely different path to solving the issue if someone has an idea.


Issue:
With my current working configuration, it can take a while for the Surround Sound receiver to detect the IR blaster. This is because the Tasmota software on my Sonoff S31 smart plug can only report the TelePeriod at the fastest, every 10 seconds. I then have to wait 11 seconds for my automation to repeat so that Home Assistant can have enough time to receive the new energy current statistics from the Sonoff S31 flashed with Tasmota. 11 seconds multiplied by the number of attempts required to get the surround sound receiver to turn on can cause a decent wait, sometimes of over a minute (not a massive issue, but kind of annoying).


Current Working Configuration:
With the current working configuration, the only issue is the time it takes for the surround sound to power toggle. This is because the Sonoff S31 Smart Plug can only have the TelePeriod turned down to 10 seconds at the fastest (The range is 10 seconds to 3600 seconds.). I have to repeatedly send the signal to turn on/off the Logitech z-5500 surround sound as it isn’t always responsive with the Broadlink RM4 Mini. It always responds with my Logitech Harmony 700 remote, but that can’t be tied into automation like the Broadlink RM4 mini can. My current automation is once the TV powers on/off, send the IR signal to turn on the surround sound (condition is to check the numeric value of the energy current for the smart-plug to see if it is above 0.17), then wait 11 seconds before repeating. This works, but if it takes for example 8 attempts to turn on the surround sound for some odd reason, it will take 88 seconds to turn on. I have tried moving the IR blaster, and considered mounting it to the back of the TV with some adhesive since the receiver for the surround sound is under the TV (which I would be fine with), but even that doesn’t seem to work consistently. Sometimes the surround sound turns on first try, sometimes it takes a quite a few attempts.

YAML code for Surround Sound to turn on:

alias: Surround Sound - Turn On
description: ""
trigger:
  - platform: device
    type: turned_on
    device_id: 5f711a4bcb91d4f239a05a4d7475e47c
    entity_id: 71fd1e538c93dd8e7ff598fbea588488
    domain: remote
condition: []
action:
  - repeat:
      sequence:
        - service: script.surround_sound_power_toggle
          data: {}
        - delay:
            hours: 0
            minutes: 0
            seconds: 11
            milliseconds: 0
      until:
        - condition: numeric_state
          entity_id: sensor.z5500plug_energy_current
          above: 0.17
    enabled: true
mode: restart

YAML code for Surround Sound to turn off:

alias: Surround Sound - Turn Off
description: ""
trigger:
  - platform: device
    type: turned_off
    device_id: 5f711a4bcb91d4f239a05a4d7475e47c
    entity_id: 71fd1e538c93dd8e7ff598fbea588488
    domain: remote
condition: []
action:
  - repeat:
      sequence:
        - service: script.surround_sound_power_toggle
          data: {}
        - delay:
            hours: 0
            minutes: 0
            seconds: 11
            milliseconds: 0
      until:
        - condition: numeric_state
          entity_id: sensor.z5500plug_energy_current
          below: 0.17
    enabled: true
mode: restart

Hardware:
Surround Sound: Logitech Z-5500
IR Blaster: Broadlink RM4 Mini
Smart Plug: Sonoff S31 (wifi) flashed with Tasmota (version: 13.2.0)
– Smart Plug communicates to Home Assistant via MQTT with Home Assistant using Mosquitto Broker 6.3.1.

Home Assistant Installation and Versions:
Raspberry Pi 4 - 8 GB (wired Ethernet, not wireless)
Installed HassOS with Raspberry Pi Imager
Home Assistant 2023.10.3
Supervisor 2023.10.0
Operating System 11.0
Frontend 20231005.0
Mosquitto Broker: 6.3.1

That was alot, even thou you left out the #script … Haven’t you considered i.e

Trigger “TV turned-on” … IF value of " sensor.z5500plug " is below 0.17 = " turn on Receiver"
Trigger “TV turned-off” … IF value of " sensor.z5500plug " is above 0.17 = " turn off Receiver"

The OP is long because I was taking guidance to from the post that describes how to make posts.

Sorry, I am not sure which script you would like to see other than the ones I provided (I provided the YAML, perhaps the code blocks aren’t showing up?). If you could guide me, I would be happy to provide them. :slight_smile:

In the automation I am already doing, I am having it repeatedly send the script to toggle the power until the Sonoff S31 has sent energy usage stats higher than 0.17, which works, it just takes a long time because I have to wait 10 seconds for the minimum threshold for TelePeriod. Unfortunately it can’t go lower.

yes i i understand( and i realized that the script(you r not showing) is a toggle, as the same IR-code is used for On-vs-OF.

I would considered using another plug (11 seconds, is a long response time, for a “local-wifi-device” usage-state changes) , and/or try with a cheap Ir-extender. https://www.amazon.co.uk/s?k=ir+extender&ref=nb_sb_noss , such works fine with the equipment i have “stashed” away in a closet (https://www.amazon.co.uk/s?k=ir+extender&ref=nb_sb_noss)

" sensor.z.5500plug_energy_current " , is that your Sonoff S31-wifi-Plug-usage( which you for some reason have flashed with tasmota), and just “named” to reflect the name of your Logitech Z-5500 ?

You could have simply asked to see the power toggle script. It didn’t seem relevant to the issue, but here it is below:

alias: Surround Sound Power Toggle
sequence:
  - service: remote.send_command
    data:
      device: surround_sound
      command: power
    target:
      entity_id: remote.broadlinkirblaster
mode: single
icon: mdi:surround-sound-5-1

In case you are wanting the Broadlink codes that this uses for “device:surround_sound” and “command: power”, it uses a file with the contents below (I don’t use volume up or volume down, I just added them in case I want to use them in the future):

{
  "version": 1,
  "minor_version": 1,
  "key": "broadlink_remote_e81656263007_codes",
  "data": {
    "surround_sound": {
      "power": "JgBQAAABIo0TEBQQEhITNRMREhESEhMREzUTNBI1FBERNhI1EzUTNBQQExATEhIRFDQSERMREhISNRM1EjUSNRQREzMTNRM1EwAFBgABIEgSAA0F",
      "vol_up": "JgBQAAABIo0UEBISExETNBUOExISEhITEDYVMxQ0ExASNRI1EzUTNBITFDMSEhQzFTIUEBISExEUMxUOEzUTEhIRFTMUMxQ0FAAFBQABH0gVAA0F",
      "vol_down": "JgBQAAABH5ASERYPERIWMhISFQ8VEBERFTMTNBUyFBEVMhM0EzUTNBMSETUVMxUzFA8VDxUPExAVMxQQFRAREhI2FDIVMhQ0EwAFBgABI0UTAA0F"
    }
  }
}

The state on/off change is immediately noticed. The TelePeriod, as seen from this Tasmota GitHub page, has a range of 10 - 3600 seconds (I obviously set this to 10, I then wait an an additional second to ensure that the data has been received by Home Assistant). This is not the on/off state change, just stats about the energy usage and other stats. I am open to trying a new plug if one is known that reports energy usage quicker. I assume you know this, but wanted to mention it, just in case, and for any future readers of this post.

The range of the IR blaster to the receiver of the surround sound isn’t the problem. I can literally have them a couple inches apart and there is zero difference oddly, unless perhaps that is not what you’re indicating and you think that a different IR receiver could help the situation?

The plug name is z5500plug. The sensor for the energy current is in Home Assistant as an entity, which is named “sensor.z5500plug_energy_current” automatically upon the import process.

Since it seems that you want to know why I would flash Tasmota on the smart plug, the Tasmota software enables this device to have more features within Home Assistant, such as the energy current statistics, which is exactly what I wanted. If I didn’t flash the firmware with Tasmota, the current setup wouldn’t be possible. I just didn’t realize before the purchase that the TelePeriod was limited to 10 seconds at the quickest. Some hurdles you only discover when actually attempting the solution.