Finally - a cheap WIRELESS switch that dims! Xiaomi Switch Gen1

That’s a shame, I’m not familiar for LimitlessLED.

How does HomeAssistsnt communicate with them? via a gateway over IP? Might just be a latency thing?

Is there any firmware out there that lets you flash the bulb to connect directly to WiFi? Do the bulbs communicate with the gateway/remote via WiFi?

Just had a look at the product page and interested to see GU10’s I need a RGB GU10 solution for my kitchen and AILight only compatible with E27 Screw bulbs at the moment.

the communication is handled over a server hub device, I am using the v3 version of the hub. The current version is 6, it might have a better chance with the dimming scripts/system. I am not sure.
I also have the limitlessled component on homebridge. In that package the delay and repetition can be entered in the configuration. That same functionality if it were available here in homeassistant too, might do the trick. As before just speculating here.

I have v4 limitlessled and haven’t been able to get this working either, I assumed I’d made a mistake in copying the code somewhere, thanks for posting that @sendorm

I also have lifx and xiaomi philips bulbs so might give it a shot with those instead. I was just trying to get it working on one bulb first before mass replicating.

Not all smart bulbs are as good at handling a steam of brightness change requests,
I just received a colour yeelight yesterday from China, and I found it was not as responsive to successive brightness changes as my hue bulbs.

How did you connect the button to HA, did you use a zigbee receiver or the xiaomi gateway?

I’m using a gateway

Hi, I’m very new with home assistant, and I’m very confused with the syntax, on one side you need to make a Jason template you use the configuration tools how ever, you use yaml on the configuration and not everything is supported through the configuration assistant.

Anyways, I want to use your script, and I can’t find a way to make work beacuse I don’t know how to translate it to the new “automation”, “script” files syntax.

any help how to will be appreciated.

also, I want to add that I have some simple automation working turning on and off light

Note: running Home Assistant v0.57.3 Docker Container on Synology NAS

For all of those yaml noob - like me, I have created package for this automation.
Here is what you have to do:

In your config folder you can create a packages folder, and add this entry in your configuration.yaml:

packages: !include_dir_named packages

Here is the configuration.yaml example .- !include_dir_named packages` has to be under homeassistant!

homeassistant:
  name: Home
  latitude: !secret lat
  longitude: !secret long
  elevation: 110
  unit_system: metric
  time_zone: Europe/Zagreb
  customize: !include customize.yaml
  packages: !include_dir_named packages

inside packages folder create new yaml file for example dim_light.yaml, and copy this in there

automation:
 - alias: xiaomi brighten on
   initial_state: 'on'
   trigger:
     - platform: event
       event_type: click
       event_data:
         entity_id: binary_sensor.switch_YOURSENSORID
         click_type: long_click_press
   condition:
     condition: and
     conditions:
     - condition: state
       entity_id: input_boolean.rgb_dim
       state: 'off'
     - condition: state
       entity_id: light.YOURLIGHT
       state: 'on'
   action:
     - service: script.turn_on
       entity_id: script.brighten_rgb_traka

 - alias: xiaomi brighten off
   initial_state: 'on'
   trigger:
     - platform: state
       entity_id: binary_sensor.switch_YOURSENSORID
       from: 'on'
       to: 'off'
   condition:
     condition: and
     conditions:
     - condition: state
       entity_id: input_boolean.rgb_dim
       state: 'off'
     - condition: state
       entity_id: light.YOURLIGHT
       state: 'on'
   action:
     - service: input_boolean.turn_on
       entity_id: input_boolean.rgb_dim
      
 - alias: xiaomi dim on
   initial_state: 'on'
   trigger:
     - platform: event
       event_type: click
       event_data:
         entity_id: binary_sensor.switch_YOURSENSORID
         click_type: long_click_press
   condition:
     condition: and
     conditions:
     - condition: state
       entity_id: input_boolean.rgb_dim
       state: 'on'
     - condition: state
       entity_id: light.YOURLIGHT
       state: 'on'
   action:
     - service: script.turn_on
       entity_id: script.dim_rgb_traka

 - alias: xiaomi dim off
   initial_state: 'on'
   trigger:
     - platform: state
       entity_id: binary_sensor.switch_YOURSENSORID
       from: 'on'
       to: 'off'
   condition:
     condition: and
     conditions:
     - condition: state
       entity_id: input_boolean.rgb_dim
       state: 'on'
     - condition: state
       entity_id: light.YOURLIGHT
       state: 'on'
   action:
     - service: input_boolean.turn_off
       entity_id: input_boolean.rgb_dim
      
script:
  dim_rgb_traka:
    sequence:
      - condition: state
        entity_id: input_boolean.rgb_dim
        state: 'on'
      - service: light.turn_on
        entity_id: light.YOURLIGHT
        data_template:
          brightness: '{{states.light.YOURLIGHT.attributes.brightness - 10}}'
      - service: script.turn_off
        entity_id: script.dim_rgb_traka
      - service: script.turn_on
        entity_id: script.dim_rgb_traka
  brighten_rgb_traka:
    sequence:
      - condition: state
        entity_id: input_boolean.rgb_dim
        state: 'off'
      - service: light.turn_on
        entity_id: light.YOURLIGHT
        data_template:
          brightness: '{{states.light.YOURLIGHT.attributes.brightness + 10}}'
      - service: script.turn_off
        entity_id: script.brighten_rgb_traka
      - service: script.turn_on
        entity_id: script.brighten_rgb_traka
    
input_boolean:
  rgb_dim:
    name: RGB traka Dim
    initial: off

Just replace:
YOURSENSORID with - your sensor ID :yum:
light.YOURLIGHT with your light.entity_id

6 Likes

Thanks a lot for this thread, got it working after a little bit of troubleshooting - trying it on a yeelight strip gave this error:

(MainThread) [homeassistant.core] Invalid service data for light.turn_on: expected int for dictionary value @ data['brightness']. Got '245.0'

A little bit of searching found this thread with a solution that worked:

{{ (states.light.kitchen_light_1.attributes.brightness | round(0)) - 25 }}

Hope this can help any other confused newbies like me :slight_smile:

Is there any possibility to set a max and min value?
If I dim down to long my 0-10 switch will be recognized as off in HASS and I cant dim it up until I shut it off and on again…
brightness: ‘{{states.light.YOURLIGHT.attributes.brightness - 10}}’

If you could set the minimum value for that?

Thanks mate, really nice script :smiley:

I have the same problem!

Going to give this a try now… my only problem is that i actually have 2 lights and 2 switches… i’m guessing i’ll need to put this in twice and change quite a lot of it to keep things unique?

      brightness: >-
         {% if states.light.stand.attributes.brightness > 10 %}
            {{states.light.stand.attributes.brightness - 10}}
         {% else %}
            {{ 10 }}
         {% endif %}

this will work!

1 Like

Hi there, can some one help me with this? I’m not able to dim the light, it work only one time… :confused:

automation:
 - id: comodino_andrea_brighten_on
   alias: Comodino Andrea brighten on
   initial_state: 'on'
   trigger:
     - platform: event
       event_type: click
       event_data:
         entity_id: binary_sensor.switch_158d00012641b4
         click_type: long_click_press
   condition:
     condition: and
     conditions:
     - condition: state
       entity_id: input_boolean.comodino_andrea_dim
       state: 'off'
     - condition: state
       entity_id: light.comodino_andrea
       state: 'on'
   action:
     - service: script.turn_on
       entity_id: script.brighten_comodino_andrea

 - id: comodino_andrea_brighten_off
   alias: Comodino Andrea brighten off
   initial_state: 'on'
   trigger:
     - platform: state
       entity_id: binary_sensor.switch_158d00012641b4
       from: 'on'
       to: 'off'
   condition:
     condition: and
     conditions:
     - condition: state
       entity_id: input_boolean.comodino_andrea_dim
       state: 'off'
     - condition: state
       entity_id: light.comodino_andrea
       state: 'on'
   action:
     - service: input_boolean.turn_on
       entity_id: input_boolean.comodino_andrea_dim
      
 - id: comodino_andrea_dim_on
   alias: Comodino Andrea dim on
   initial_state: 'on'
   trigger:
     - platform: event
       event_type: click
       event_data:
         entity_id: binary_sensor.switch_158d00012641b4
         click_type: long_click_press
   condition:
     condition: and
     conditions:
     - condition: state
       entity_id: input_boolean.comodino_andrea_dim
       state: 'on'
     - condition: state
       entity_id: light.comodino_andrea
       state: 'on'
   action:
     - service: script.turn_on
       entity_id: script.dim_comodino_andrea

 - id: comodino_andrea_dim_off
   alias: Comodino Andrea dim off
   initial_state: 'on'
   trigger:
     - platform: state
       entity_id: binary_sensor.switch_158d00012641b4
       from: 'on'
       to: 'off'
   condition:
     condition: and
     conditions:
     - condition: state
       entity_id: input_boolean.comodino_andrea_dim
       state: 'on'
     - condition: state
       entity_id: light.comodino_andrea
       state: 'on'
   action:
     - service: input_boolean.turn_off
       entity_id: input_boolean.comodino_andrea_dim
      
script:
  dim_comodino_andrea:
    sequence:
      - condition: state
        entity_id: input_boolean.comodino_andrea_dim
        state: 'on'
      - service: light.turn_on
        entity_id: light.comodino_andrea
        data_template:
          brightness: '>-
             {% if states.light.comodino_andrea.attributes.brightness > 10 %}
               {{states.light.comodino_andrea.attributes.brightness - 10}}
             {% else %}
               {{ 10 }}
             {% endif %}'
      - service: script.turn_off
        entity_id: script.dim_comodino_andrea
      - service: script.turn_on
        entity_id: script.dim_comodino_andrea
  brighten_comodino_andrea:
    sequence:
      - condition: state
        entity_id: input_boolean.comodino_andrea_dim
        state: 'off'
      - service: light.turn_on
        entity_id: light.comodino_andrea
        data_template:
          brightness: '{{states.light.comodino_andrea.attributes.brightness + 10}}'
      - service: script.turn_off
        entity_id: script.brighten_comodino_andrea
      - service: script.turn_on
        entity_id: script.brighten_comodino_andrea
    
input_boolean:
  comodino_andrea_dim:
    name: Comodino Andrea Dim
    initial: off

The problem starts with sram bulbs, with hue everything is working. Maybe sram lightly doesn’t play well with dimming?!
:confused:

I love packages @INTEL! It’s really a nice way of including new smart features in HASS without messing around in several different configurations files.

However, I can’t get your package to work. :frowning: I’m trying to dim a Z-Wave ligh included through a Vera. Maybe this way of using Xiaomi switches only works for light devices directly included in HASS that have the dim feature?

Glad I could help :slight_smile:
If your lights or component you are using doesn’t support dim, you cannot use this.

The lights are of course dimmable! I’ve added the package as written and switched the parts with my own devices. However, nothing happens when I press the button. If I turn on the dimmable light and long press the light dim down to 0%. If I press again it never turn on or dim up.