Combining Z-wave Relay with Milight light

I have a question on the best way to configure my lights + wall switches:

In the house I have (z-wave) switches (show up in HA as switch.entity_id) that have lights behind them, these lights are CCT + RGB, they remember their state after power loss and show up in home-assistant using the MQTT JSON component as light.entity_id. (they are Milight bulbs controlled by GitHub - sidoh/esp8266_milight_hub: Replacement for a Milight/LimitlessLED hub hosted on an ESP8266 )

What I want to do is to combine these two components and have them show as 1 light. Of which the turn_on, turn_off and toggle switches the switch, but any other setting (brightness, color, white_value) should modify the mqtt light.

I’ve been looking into how to configure this, and I’m not sure I can do this with the “MQTT Template Light” or “Template Light” or that I need to start working with automations or scripts.

Is there anyone who has a similar set-up or some tips on how to get started with something like this? Thanks :slight_smile:

EDIT:
I’m going to try to combine at least the switch with the brightness of the milights. The color / white_temperature etc I will arrange via scenes / seperate identities. I’ll keep this thread updated with my findings/struggles.

EDIT2:
First try:

light:
  - platform: template
    lights:
      woonkamer:
        friendly_name: “Woonkamerverlichting”
        entity_id:
          - switch.relais_woonkamer_eettafel_een
          - light.woonkamer_eettafel
        value_template: “{{states.switch.relais_woonkamer_eettafel_een.state}}”
        level_template: “{{states.light.woonkamer_eettafel.attributes.brightness}}”
        turn_on:
          service: switch.turn_on
          entity_id: switch.relais_woonkamer_eettafel_een
        turn_off:
          service: switch.turn_off
          entity_id: switch.relais_woonkamer_eettafel_een
        set_level:
          service: light.turn_on
          entity_id: light.woonkamer_eettafel
          data_template:
            brightness: “{{ brightness }}”

Progress!

Hi @tbrasser

I would recommend changing the value_template because you are using the state of a platform that maybe takes extra time to load, the Template Light may get an unknown state during startup.

value_template: “{{states.switch.relais_woonkamer_eettafel_een.state}}”

Change it to this:

value_template: >-
  {% if is_state('switch.relais_woonkamer_eettafel_een', 'on') %}
    on
  {% else %}
    off
  {% endif %}

Cheers!

1 Like

I’ve done that now, warnings/errors due to that in the log are gone as-well. thanks for the tip.

So now I have my z-wave switches and milight lights combined via template lights, everything seems to work. (well: on,off, and brightness atleast)

Is there a way I can also send a switch.turn_on command to the switches when changing the brightness when the light is initially off? Also I’d like to not send light.turn_on commands to my lights when changing the brightness, because when I’m doing this to fast, the milights think they should go into pairing mode since they received the on command 3 times within a few seconds.

@tbrasser: Have you tried using switch.turn_on in the set_level?

set_level:
  service: switch.turn_on
  entity_id: switch.relais_woonkamer_eettafel_een
  data_template:
    brightness: “{{ brightness }}”

I’m not sure if the “switch.turn_on” can pass brightness, but it’s maybe worth a try? So when brightness changes it should do “switch.turn_on” with a data_template containing “brightness”.

Scratch that.
Maybe you can have multiple entities in your set_level, like this:

set_level:
  - service: light.turn_on
    entity_id: light.woonkamer_eettafel
    data_template:
      brightness: “{{ brightness }}”
  - service: switch.turn_on
    entity_id: switch.relais_woonkamer_eettafel_een
    data_template:
      brightness: “{{ brightness }}”

I’m strugling with this to.

I got this now:

- platform: template
  lights:
    test:
      friendly_name: "Test"
      entity_id: switch.test
      turn_on:
        service: switch.turn_on
        entity_id: switch.test
      turn_off:
        service: switch.turn_off
        entity_id: switch.test
      set_level:
        service: light.turn_on
        data_template:
          brightness: "{{ brightness }}"
          entity_id: light.eettafel
      set_temperature:
        service: light.turn_on
        data_template:
          value: "{{ color_temp }}"
          entity_id: light.eettafel
      set_color:
        service: light.turn_on
        data_template:
          value: "{{ h }}"
          entity_id: light.eettafel

I can set the brightness and the eettafel is light is responding.
I also see the color and temperature settings but it doesn’t work.

Can you help me?