MagicHome with IR working using ESPHome

Tags: #<Tag:0x00007f73a5b19c28>

Picking up where @Luuk_Neele left off with these devices here.

I got the ESPHome config figured out for supporting the remote control.
You just need to define a remote_receiver. ESPHome can pick up the IR commands perfectly when configured for nec commands. From there it’s a matter of tediously defining a binary_sensor for each button and the action you want to take.

Here’s a fully working config that mimics the remote behaviour from the factory.

  name: mh_ledstrip3
  platform: ESP8266
  board: esp8285

wifi:
  ssid: !secret ssid
  password: !secret ssid_pass
  manual_ip:
    static_ip: !secret ip_mh_ledstrip3
    gateway: !secret gateway
    subnet: !secret subnet

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: !secret api_pass

ota:
  password: !secret ota_pass
  
light:
  - platform: rgb
    name: mh_ledstrip3
    id: mh_ledstrip3
    red: pwm_r
    green: pwm_g
    blue: pwm_b
    restore_mode: ALWAYS_ON

output:
  - platform: esp8266_pwm
    pin: GPIO12
    frequency: 1000 Hz
    id: pwm_g

  - platform: esp8266_pwm
    pin: GPIO5
    frequency: 1000 Hz
    id: pwm_r

  - platform: esp8266_pwm
    pin: GPIO13
    frequency: 1000 Hz
    id: pwm_b
  
remote_receiver:
  pin:
    number: GPIO4
    inverted: true
  dump: nec
  
binary_sensor:
  - platform: remote_receiver
    id: "on"
    nec:
      address: 0x00FF
      command: 0xB04F
    on_press:
      then:
        - light.turn_on:
            id: mh_ledstrip3
  - platform: remote_receiver
    id: "off"
    nec:
      address: 0x00FF
      command: 0xF807
    on_press:
      then:
        - light.turn_off:
            id: mh_ledstrip3
  - platform: remote_receiver
    id: brightness_up
    nec:
      address: 0x00FF
      command: 0x906F
    on_press:
      then:
        - light.dim_relative:
            id: mh_ledstrip3
            relative_brightness: 20%
  - platform: remote_receiver
    id: brightness_down
    nec:
      address: 0x00FF
      command: 0xB847
    on_press:
      then:
        - light.dim_relative:
            id: mh_ledstrip3
            relative_brightness: -20%
  - platform: remote_receiver
    id: red
    nec:
      address: 0x00FF
      command: 0x9867
    on_press:
      then:
        - light.turn_on:
            id: mh_ledstrip3
            red: 100%
            green: 0
            blue: 0
  - platform: remote_receiver
    id: green
    nec:
      address: 0x00FF
      command: 0xD827
    on_press:
      then:
        - light.turn_on:
            id: mh_ledstrip3
            red: 0
            green: 100%
            blue: 0
  - platform: remote_receiver
    id: blue
    nec:
      address: 0x00FF
      command: 0x8877
    on_press:
      then:
        - light.turn_on:
            id: mh_ledstrip3
            red: 0
            green: 0
            blue: 100%
  - platform: remote_receiver
    id: white
    nec:
      address: 0x00FF
      command: 0xA857
    on_press:
      then:
        - light.turn_on:
            id: mh_ledstrip3
            red: 100%
            green: 100%
            blue: 100%
  - platform: remote_receiver
    id: R2
    nec:
      address: 0x00FF
      command: 0xE817
    on_press:
      then:
        - light.turn_on:
            id: mh_ledstrip3
            red: 100%
            green: 35%
            blue: 14%
  - platform: remote_receiver
    id: R3
    nec:
      address: 0x00FF
      command: 0x02FD
    on_press:
      then:
        - light.turn_on:
            id: mh_ledstrip3
            red: 100%
            green: 57%
            blue: 14%
  - platform: remote_receiver
    id: R4
    nec:
      address: 0x00FF
      command: 0x50AF
    on_press:
      then:
        - light.turn_on:
            id: mh_ledstrip3
            red: 100%
            green: 78%
            blue: 28%
  - platform: remote_receiver
    id: R5
    nec:
      address: 0x00FF
      command: 0x38C7
    on_press:
      then:
        - light.turn_on:
            id: mh_ledstrip3
            red: 100%
            green: 100%
            blue: 0%
  #Greens
  - platform: remote_receiver
    id: G2
    nec:
      address: 0x00FF
      command: 0x48B7
    on_press:
      then:
        - light.turn_on:
            id: mh_ledstrip3
            red: 28%
            green: 100%
            blue: 28%
  - platform: remote_receiver
    id: G3
    nec:
      address: 0x00FF
      command: 0x32CD
    on_press:
      then:
        - light.turn_on:
            id: mh_ledstrip3
            red: 28%
            green: 100%
            blue: 64%
  - platform: remote_receiver
    id: G4
    nec:
      address: 0x00FF
      command: 0x7887
    on_press:
      then:
        - light.turn_on:
            id: mh_ledstrip3
            red: 28%
            green: 64%
            blue: 100%
  - platform: remote_receiver
    id: G5
    nec:
      address: 0x00FF
      command: 0x28D7
    on_press:
      then:
        - light.turn_on:
            id: mh_ledstrip3
            red: 14%
            green: 35%
            blue: 100%
  #Blues
  - platform: remote_receiver
    id: B2
    nec:
      address: 0x00FF
      command: 0x6897
    on_press:
      then:
        - light.turn_on:
            id: mh_ledstrip3
            red: 14%
            green: 14%
            blue: 100%
  - platform: remote_receiver
    id: B3
    nec:
      address: 0x00FF
      command: 0x20DF
    on_press:
      then:
        - light.turn_on:
            id: mh_ledstrip3
            red: 46%
            green: 28%
            blue: 100%
  - platform: remote_receiver
    id: B4
    nec:
      address: 0x00FF
      command: 0x708F
    on_press:
      then:
        - light.turn_on:
            id: mh_ledstrip3
            red: 81%
            green: 28%
            blue: 100%
  - platform: remote_receiver
    id: B5
    nec:
      address: 0x00FF
      command: 0xF00F
    on_press:
      then:
        - light.turn_on:
            id: mh_ledstrip3
            red: 100%
            green: 14%
            blue: 78%

This works perfectly with home assistant. Using the remote instantly updates HA with the right state, and the remote works locally on the device so even if HA is off, it still changes the colors.

Note: this config is setup so that the individual buttons don’t show up in HA as sensors. If you want them to give each one a name property instead of just an id.

I assume this can be extended to handle RGBW and RGBWW devices as well.

12 Likes

Hmmm do you think this will work with the RF version ?

I don’t have one to try out but looking here I don’t see why not.

The remote_receiver component lets you receive and decode any remote signal, these can for example be infrared remotes or 433MHz signals.

If it doesn’t just work, switch dump:nec to dump:all and watch the logs to see which type of interpretation produces clean data.

Brillant , though i just flashed my device and blue/red seen to have gone.IM not sure why as nothing changed on my setup GPIO wise

Maybe the pinout is different on the RF version? Does your previous config work if you flash it again? Maybe the GPIO config is just different.

I didnt change the GPIO config and after multiple updating I have Blue and Green back just red has gone awol. Im going to try reflashing via the laptop as OTA seems to be failing now depsite it sayng complete

FYI for anyone that wants to use the Flash/Strobe/Fade/Smooth buttons on the IR remote, here are the NEC command codes for those:

  • Flash: 0xB24D
  • Strobe: 0x00FF
  • Fade: 0x58A7
  • Smooth: 0x30CF

You can link those buttons to ESPHome’s built-in effects (https://esphome.io/components/light/index.html#light-effects) or define your own. Example

light:
  - platform: rgbw
    effects:
      - random:
...

and then

binary_sensor:
  - platform: remote_receiver
      id: smooth
      nec:
        address: 0x00FF
        command: 0x30CF
      on_press:
        then:
          - light.turn_on:
              id: rgbw_01
              effect: random
1 Like

Didn’t realize I missed those. Thanks for figuring those out!

Has there been anymore work with this or does it live in a repo somewhere? I have a RGBW version and would love to be able to control the white channel. https://esphome-configs.io/ would also be a perfect place to upload a fully working config.

That’s the full config in the original post. The remote trigger sections can be used to trigger any light controller so making it support rbgw would just be a matter of using regular rgbw properties.

Did you used some kind of color or gamma correction ?
I used your config , but the color and brightness is quite off .

Thanks.