Smart bulbs with Smart switches - how to combine and integrate them?

So now I’m starting to add Smart bulbs to my house. Originally I only had smart switches. Everything in my house is connected to a dimmable, programmable switch.

How are people integrating these two? Do I rip out the smart switches? Do I program the switches to control the bulbs? If I do program the switches, I would have to bridge the tech in HASS so maybe with AppD?

Maybe someone has written a custom component that already integrates the two?

I love the fact that I can select the color and temperature of light in the room but man!! Things are getting complicated!

1 Like

You ain’t seen nothin’ yet!

So, to answer your first three questions, yes/no, yes/no, and finally, yes/no.

The problem with composing a serious reply is because there are dozens of different smart bulbs and dozens of different smart switches. Some are WiFi, some are Z-wave and at least one is Bluetooth. There’s also 433MHz stuff. Some smart things even have their own secret protocol. Some smart lights and switches require a hub, some don’t; it depends on the protocol used.

Don’t ask for recommendations. At least not until you do some research. If you ask 100 users on this forum what they use, you will get 100 different replies. In my case, since I am a tinkerer, I have a mix of almost every possible protocol in my home. Maybe I’ve just been lucky, but by far, the most reliable is Z-Wave, but your mileage may vary.

So, to answer your last question- one would need to know which lights and switches you are using before even venturing a guess at an answer.

Hope this helps.

1 Like

I was hoping the response would be generic and connect the two using the states and attributes in hass.

If you must know, I’m using UPB switches and zigbee2mqtt bulbs.

I was just looking around and found https://www.home-assistant.io/components/light.template/

…but it doesn’t support colors.

Then someone tried to get it into hass but hasn’t succeeded https://github.com/home-assistant/home-assistant/pull/12439/

Decouple the smart light switch from the smart light and control the light with the switch only through home assistant

1 Like

And when HA is down nothing will work? I am not suicidal so I would avoid that

Then you’re in a pickle. When your switch cuts power your bulbs aren’t smart anymore so you have to choose which scenario you prefer more

I have a hard time to understand the reason for having a smart switch AND a smart bulb for the same light. But thats me

1 Like

I run smart switches (xiaomi switches) and tradfri bulbs together Two clusters of three bulbs on one xiaomi switch in the living room with an open plan dinning room . This is because xiaomi do not support dimming and I like the ability to dim the lights to preset modes .

Also I do not like the idea of using smart bulbs with a constant circuit and using wireless switches to turn them off and on . I use a template sensor to workout when the tradfri bulbs are unavailable and “stack up commands” until the sensor tells me they are online. Tradfri bulbs take about a minute to come on line when power is restored , they also remember their last “on” settings . If you continually turn the power off and on , they can get very confused, but it does take some effort. If you do it 6 times they reset !

if I switch the bulbs off via automation’s or alexa . I only turn the bulbs off . After two mins of inactivity and if the bulbs are still off , I then turn them off at the switch. This protects against automation’s failing and continuity turning the switch on and off (I’m a bad programmer and have reset my bulbs more than once !) .
I can supply code , but I use Appdamon Python scripts

Its Neat solution as I can turn off or dim individual bulbs without having too add additional light switches

@lonebaggie Yes, please share your appd script. I have a feeling I’m going to be appd’ing it up a lot on this one. I really would prefer the template but my python is not good enough to get that working.

I did notice I went into my office this morning and turned on the light and it was red. These smart bulbs appear to save the state a little too well. I’m going to have to program around this issue.

I was thinking about trying to create a virtual light with appd but that sounds like a lot of work any maybe not even possible. Also I’m still thinking about how I can leverage some of the features of the smart switch to control the light. Double-tap, hold, etc. All of that is also going to be a challenge because none of those features are HASS aware.

I really need @jameshilliard’s UPB component with full UPB support that he’s been talking about writing. :slight_smile:

see these posts

The trick is working out how the bulbs and HA react when the power is removed from the smart bulb . Does HA report the bulbs are available/unavailable . How long they take to re-sync. If the bulbs don’t report correctly or reliably the solution wont work.

I could not get my tradfri bulbs to work reliably with zigbee2mqtt , failed did’nt like the bulbs going offline, kept crashing.

Thanks!
Okay, I just tried it and it worked too well. I pressed the wall switch, the light came on red (because it was red before it went off, and about four seconds later it turned 4k temp, full brightness. I guess zigbee2mqtt queued it up until it was “communicating”. Impressive. It’s a Sengled bulb.

class SmartBulbSwitch(hass.Hass):

  def initialize(self):
    self.listen_state(self.state_change, self.args["switch"])

  def state_change(self, entity, attribute, old, new, kwargs):
    if new == "on":
      self.call_service('light/turn_on', entity_id=self.args["bulb"], 
                        color_temp=287, brightness=255)

This is the log

Apr 02 19:21:24 appdaemon[16676]: 2019-04-02 19:21:24.628098 WARNING AppDaemon: OfficeBulbSwitch                                                           [16/1818]
Apr 02 19:21:48 appdaemon[16676]: 2019-04-02 19:21:48.763308 INFO AppDaemon: Terminating OfficeBulbSwitch
Apr 02 19:21:48 appdaemon[16676]: 2019-04-02 19:21:48.763552 INFO AppDaemon: Reloading Module: /opt/appdaemon-cfg/apps/smart_bulb_and_switch.py
Apr 02 19:21:48 appdaemon[16676]: 2019-04-02 19:21:48.765734 INFO AppDaemon: Initializing app OfficeBulbSwitch using class SmartBulbSwitch from module smart_bulb_and_switch
Apr 02 19:22:17 zigbee2mqtt:info 4/2/2019, 7:22:17 PM MQTT publish: topic 'zigbee2mqtt/router_hallway', payload '{"state":false,"linkquality":34,"last_seen":1554258137414}'
Apr 02 19:22:22 zigbee2mqtt:info 4/2/2019, 7:22:22 PM Zigbee publish to device '0xb0ce181400052828', genLevelCtrl - moveToLevelWithOnOff - {"level":255,"transtime":0} - {"manufSpec":0,"disDefaultRsp":0} - null
Apr 02 19:22:22 zigbee2mqtt:info 4/2/2019, 7:22:22 PM MQTT publish: topic 'zigbee2mqtt/zb_office_ceiling1', payload '{"state":"ON","linkquality":36,"last_seen":1554184437820,"brightness":255,"color_temp":351,"color":{"x":0.38,"y":0.17},"color_mode":1}'
Apr 02 19:22:22 zigbee2mqtt:info 4/2/2019, 7:22:22 PM MQTT publish: topic 'zigbee2mqtt/zb_office_ceiling1', payload '{"state":"ON","linkquality":36,"last_seen":1554258142830,"brightness":255,"color_temp":351,"color":{"x":0.38,"y":0.17},"color_mode":1}'
Apr 02 19:22:22 zigbee2mqtt:info 4/2/2019, 7:22:22 PM Zigbee publish to device '0xb0ce181400052828', lightingColorCtrl - moveToColorTemp - {"colortemp":287,"transtime":0} - {"manufSpec":0,"disDefaultRsp":0} - null
Apr 02 19:22:23 zigbee2mqtt:info 4/2/2019, 7:22:23 PM Zigbee publish to device '0xb0ce181400052828', genLevelCtrl - read - [{"attrId":0}] - {"manufSpec":0,"disDefaultRsp":0} - null
Apr 02 19:22:23 zigbee2mqtt:info 4/2/2019, 7:22:23 PM MQTT publish: topic 'zigbee2mqtt/zb_office_ceiling1', payload '{"state":"ON","linkquality":36,"last_seen":1554258143273,"brightness":255,"color_temp":351,"color":{"x":0.38,"y":0.17},"color_mode":1}'
Apr 02 19:22:23 zigbee2mqtt:info 4/2/2019, 7:22:23 PM Zigbee publish to device '0xb0ce181400052828', lightingColorCtrl - read - [{"attrId":3},{"attrId":4},{"attrId":7}] - {"manufSpec":0,"disDefaultRsp":0} - null
Apr 02 19:22:23 zigbee2mqtt:info 4/2/2019, 7:22:23 PM MQTT publish: topic 'zigbee2mqtt/zb_office_ceiling1', payload '{"state":"ON","linkquality":34,"last_seen":1554258143511,"brightness":255,"color_temp":287,"color":{"x":0.38,"y":0.17},"color_mode":1}'
Apr 02 19:22:23 zigbee2mqtt:info 4/2/2019, 7:22:23 PM MQTT publish: topic 'zigbee2mqtt/zb_office_ceiling1', payload '{"state":"ON","linkquality":34,"last_seen":1554258143513,"brightness":255,"color_temp":287,"color":{"x":0.38,"y":0.17},"color_mode":1}'

Better than the 50 odd seconds for the tradfri. I use a template sensor rather than trigger the default bulb settings from the switch going on . I trigger when the sensor comes on . I also slowly fade to the default level.

- platform: template
    sensors:
      lrsync:
        friendly_name: 'Livingroom Light Sync'
        value_template: >-
          {% if is_state('light.lr1', 'unavailable') 
          and is_state('light.lr2', 'unavailable') 
          and is_state('light.lr3', 'unavailable') 
          and is_state('light.dr1', 'unavailable') 
          and is_state('light.dr2', 'unavailable') 
          and is_state('light.dr3', 'unavailable')  %}
            off
          {% elif not is_state('light.lr1', 'unavailable') 
          and not is_state('light.lr2', 'unavailable') 
          and not is_state('light.lr3', 'unavailable') 
          and not is_state('light.dr1', 'unavailable') 
          and not is_state('light.dr2', 'unavailable') 
          and not is_state('light.dr3', 'unavailable')  %}
            on
          {% else %}
            off
          {% endif %}

I have an item select, which I can manipulate via lovelace or alexa

  light_state:
    name: Living Room Light State
    options:
     - "Off"
     - Dark
     - Relaxed
     - Bright
    icon: mdi:lightbulb

This program then triggers when the sensor.lrsysnc turns on. If the lights were triggered by the item select, the switch which controls the power has already been turned and the bulbs are ready. If the sensor.lrsync was triggered by the physical switch being turned on I force the item select to relaxed .

# Program to sync Tradfri lights when power restored
import appdaemon.plugins.hass.hassapi as hass
class LRsync(hass.Hass):
    def initialize(self):
        self.listen_state(self.lrsync,"sensor.lrsync",new="on")
    def lrsync(self, entity, attribute, old, new, kwargs):
        self.log("sync triggered")
# if triggered by switch turned on,  default lights to relaxed 
# Also ensure Alexa is silent as not invoked by mood item select
        if self.get_state("input_select.light_state") == "Off" :
            self.select_option("input_select.light_state", "Relaxed")
# run delayed option from item select now lights are in sync
        if self.get_state("input_select.light_state") == "Dark":
            self.dark()
        if self.get_state("input_select.light_state") == "Relaxed" :
            self.relaxed()
        if self.get_state("input_select.light_state") == "Bright":
                self.bright()
# default setting for dark ,relaxed and bright 
    def dark(self):
        self.call_service("light/turn_on", entity_id = "light.all_living_room_lights", brightness = 25, transition = 6 , color_temp = 450)
        self.log("dark triggered")
    def relaxed(self):
        self.call_service("light/turn_on", entity_id = "light.all_living_room_lights", brightness = 203, transition = 6 , color_temp = 367)
        self.log("relaxed triggered")
    def bright(self):
        self.call_service("light/turn_on", entity_id = "light.all_living_room_lights", brightness = 254, transition = 6 , color_temp = 250)
        self.log("bright triggered")

Your sync seems much quicker than mime , suspect that’s why I had to drop using zigbee2mqtt as I was getting timeouts on the mqtt server . Still triggering on a sensor, or (if a single bulb) the bulb coming on would stop having to rely on the mqtt server buffering the commands, at the end of the day whatever works :slight_smile:

Hi,

I wanted to share my solution to this problem which is a little different. And get some feedback on how to improve it.

I have a Z-wave Wall Light Switch with Dimmer (Leviton DZ6HD:Amazon.com ). This controls two scones in the wall and with automation, also controls a floor lamp that is connected to a Minoston Z-wave Plug with Dimmer (Amazon.com). Through home assistant, I use the Wall Light Switch to control the on/off of the scones and the lamp, and to keep the brightness levels in sync. I then bought 2 Philips Hues Smart Bulbs that I put into the scones. I already have a Hub and added them to the hub. I created a zone for the two bulbs.

My goal was:
1. To be able to use both home assistant and the wall switch to turn the Scones with the bulbs on and off
2. To be able to use both home assistant and the wall switch to set the brightness

Challenges:
The biggest challenge, as most know, is that using the wall switch dimmer reduces power to the bulbs and then at some point the Hue bulbs will cease to function. So I needed to limit how low a person could set the dimmer using the wall switch.

Solution:
• The Leviton switch has the ability to set the minimum dim level, and, using z-wave device configuration, I set it to 50%. This means that using either the physical dimmer or the HA entity for it, I can’t set the brightness level below 127.5 (half of 255). That being said, on the wall switch, I can still move the dimmer values up and down. To the person touching it, they can’t tell zero is close to 127.5.
• I created a Template Light (Template Light - Home Assistant) that is a combination of the Wall Switch and the Hue Bulbs. I used the on/off for the wall switch and the dimmer change using it. As you can see in my example, I translated the Wall Switch brightness values from 127.5 to 255 to reflect 0 to 255
• I created an automation so that whenever the Wall Switch brightness values are changed I update the Hues Bulb and the Floor Lamp. I set it to Restart Mode in case you press the dimmer switch too quickly (does that make sense?)
• I will probably replace the Lamp with a Hue Bulb and that will simplify my solution as I can just add the Bulb to the existing Zone, but as of now I have a separate smart plug to control the floor lamp

Issues Requesting Solutions / Feedback in General:
• Everything stays in sync as long as you don’t use the Hue App to change the brightness. If you change it, the Template Light entity shows the right value, but the Wall Switch won’t.
• The response time between touching the dimmer on the wall and see the bulbs update (brightness change) is slow
• I can’t get effects to load for the Hue Philips Zone. I believe there should be a colorloop and randomcolor?
• With the transition variable, if it isn’t used I get a transition is undefined error so I add some error handling. Is this best practice?
• Is there a better way to this or any other suggestions?

Here are the details of my solution:
Entities:
• light.living_room_foyer_bulbs → this is the Hue Philips Zone with 2 bulbs in it
• light.foyer_light → this is the Leviton Z-wave Wall Light Switch with Dimmer
• light.living_room_floor_lamp → this is the Minoston Z-wave Plug with Dimmer
• living_room_foyer_light_swtich → this is the new Template Late (I know I misspelled switch in the entity id…)

Here is what I put in configuration.yaml

  - platform: template
    lights:
      living_room_foyer_light_swtich:
        friendly_name: "Living Room Foyer"
        unique_id: "lights_template_from_wall_switch_and_hue_group_01"
        supports_transition_template: "{{ True }}"
        turn_on:
          - service: light.turn_on
            entity_id:
              - light.foyer_light
              - light.living_room_foyer_bulbs
              - light.living_room_floor_lamp
        turn_off:
          - service: light.turn_off
            entity_id:
              - light.living_room_foyer_bulbs
              - light.foyer_light
              - light.living_room_floor_lamp
        level_template: "{{ state_attr('light.living_room_foyer_bulbs', 'brightness') | int }}"
        set_level:
          - service: light.turn_on
            data_template:
              brightness: "{{ (brightness | float / (255-0)) * (255-127.5) + 127.5 }}"
              entity_id:
                - light.foyer_light
        value_template: "{{ states('light.foyer_light') }}"
        temperature_template: "{{ state_attr('light.living_room_foyer_bulbs', 'color_temp') | int }}"
        set_temperature:
          service: light.turn_on
          data:
            color_temp: "{{ color_temp }}"
            entity_id: light.living_room_foyer_bulbs
        color_template: "({{ state_attr('light.living_room_foyer_bulbs', 'hs_color')[0] }}, {{ state_attr('light.living_room_foyer_bulbs', 'hs_color')[1] }})"
        set_color:
          - service: light.turn_on
            data_template:
              entity_id:
                - light.living_room_foyer_bulbs
              hs_color:
                - "{{ hs[0] }}"
                - "{{ hs[1] }}"
              transition: "{{ ( transition|default('0.00') ) | float }}"
        # effect_list_template: "{{ state_attr('light.living_room_foyer_bulbs', 'effect_list') }}"

Here is the automation

description: >-
  When the brightness on the Foyer Light Switch changes update the Hue Bulbs &
  floor lamp brightness level.  Multiple the brightness setting by a multiplier
  since the switch is limited on the lower bound to avoid turning off power to
  the Hue Bulbs due to brightness.
trigger:
  - platform: state
    entity_id: light.foyer_light
    attribute: brightness
condition: []
action:
  - service: light.turn_on
    target:
      entity_id:
        - light.living_room_foyer_bulbs
        - light.living_room_floor_lamp
    data:
      brightness: >-
        {{ (255-0) * (state_attr('light.foyer_light', 'brightness') | float -
        127.5) / (255-127.5) + 0 }}
mode: restart

Let me know what you think!

1 Like

I really like small relays (like Sonoff MINI), which are installed behind the dummy wall switch and could be controlled EITHER remotely (e.g. via Zigbee) OR locally (push the button). In that way I don’t afraid that my HA is down - I will still have basic control over my smart bulbs (basic on-off functionality).

It would be really nice to see similar smart switch, but with DUAL mode:
Mode#1: smart button which only sends on/off commands to HA (which sends actual commands to smart bulbs) = smart bulb is always powered on
Mode#2: relay mode, which is able to control the bulb locally, without any connection to the network = smart bulb is not energized when it’s switched off.

So, #1 is a primary mode and #2 is a backup, in case HA is down (or you need to change the bulb). Changing between 1 and 2 could be done with some small/hidden push button reachable from outside, somewhere at the switch panel or behind the hatch.

Can’t understand why something like that not available still… or is it?

Smart switches with similar features are readily available.

yeah, have seen similar, but not with possibility of manual changeover to “override” functionality… :frowning: Shelly has something, but it needs to be configured via their app, I think.

Lanbon L8 with openHASP does everything and then some ….

Group - Home Assistant This was the most easiest way of setting it up, no yaml file, just click and go.