Update MQTT light from multiple milight remotes

@sidoh

I have just implemented your awesome milight remote MQTT updater and I love it! Thank you so much.

I have come across a little problem though. How do I get my MQTT lights to listen for updates from multiple remotes? i.e. I have some lights that are paired to multiple remotes and different groups so HASS front end should update the state of the lights if updates from any of the paired device_id’s are recieved.

this is my working MQTT light HASS config:

light: 
  • name: “Bedroom TV Right”
    command_topic: milight/0xCD88/rgbw/1
    state_topic: milight/states/0xCD88/rgbw/1
    <<: &MILIGHT_PARAMS
    platform: mqtt_json
    rgb: true
    brightness: true

and I’ve tried stuff like this with and without quotes around the state_topic entries and stuff but configurator doesn’t like it:

light: 
  • name: “Bedroom TV Right”
    command_topic: milight/0xCD88/rgbw/1
    state_topic: milight/states/0xCD88/rgbw/1 , milight/0xDD66/rgbw/2
    <<: &MILIGHT_PARAMS
    platform: mqtt_json
    rgb: true
    brightness: true

I was hoping I could just put a list of topics in there but I guess not. Is there a way of using a template to insert different id’s or something??

Do I need an automation to intercept the incoming MQTT message from the additional remotes and then publish a new message containing the data from the previous message but change the device_id to that which is listed in the MQTT light configuration?

Each light would have to be paired individually but then one could make a card for each light with a configurable list of remotes to listen to in real-time

I guess that is what I will try now. I’ll scribble down some code now and add to this thread once I have something.

Thank you again for sharing this. I’m having a great time with it!

Hi,

There’s not really a great way to solve this. The mqtt_json platform is limited to a single state topic, and espMH only cares about deviceid/groupid pairs (i.e., there’s no way to tell it to bind certain pairs together).

The clean only ways I can think of to solve this are:

  1. Add a feature to espMH to allow users to bind states together
  2. Add a new HASS component that allows states to be merged together

(1) Is probably the cleanest thing, but also difficult to do efficiently. Unfortunately don’t think I’ll have time to look at either of these things soon, but happy to collaborate with anyone that’s interested.

The solution you’re suggesting might work, but my guess is it’ll have funky problems. If I’m wrong, let me know becaue I think others would find this useful :slight_smile:

I am not entirely clear about the milight side, but can you trigger and automation from the second mqtt topic to turn the light on or orff?

Hi all,

Wouldn’t an automation be simpler, thus deal with it in HA only?

State of the individual remotes is already published by MH in MQTT so it can be copied to the state of the light setup in HA. I think that if paired 1:1 (group 1 of remote 0x1111 to group 3 of remote 0x2222 and to group 1 of remote 0x3333) then in HA only one of these needs to be set.

Also, it can be useful when having individual lights paired with different remotes and the group made of these individual lights controlled with another remote: light A controlled by remote 0x1111, light B controlled by remote 0x2222 and A+B controlled by remote 0x3333 (which can be controlled as a group and individually - such as the Hue scenes where the light bulbs in a room have different colors). When the remote 0x3333 is used then the state of both 0x1111 and 0x2222 remotes should be updated, however if 0x1111 is used then update only light A (similar to pairing A to group 1 and B to group 2 of the same remote thus A+B can be controlled by group 0).

- alias: Sync Remotes
  initial_state: True
  trigger:
    - platform: mqtt
      topic: 'milight/states/0xDD66/rgbw/2'
    - platform: mqtt
      topic: 'milight/states/0xAAAA/rgbw/3' #or other remote id
  action:
    - service: mqtt.publish
      data_template:
        topic: 'milight/states/0xCD88/rgbw/1'
        payload_template: '{{ trigger.payload }}'