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

I very nearly did that until I sat down for hours to figure out the long press.

My double clicks are generally used for shut down away or bedtime scripts now. Might have a play with them to so they toggle between “morning” and “night time” scripts and scenes.

Sounds like we have similar automations. I love my automation to turn off all the lights.

If anyone else is as dim[1] as me, the code is revealed when you click the right arrow/triangles in the first post, on the left of “Input Boolean” etc.

[1] see what I did there?

4 Likes

@badgerhome Are you liking the ARILUX bulbs? Do they have a nice warm white too?

I am. You can achieve a warmer white. I will share a video of my bed side lamps with are warmer. Not as warm as a Hue or a traditional halogen though but I feel they are acceptable. I prefer the white cold lighting in the hallways, just makes seeing thing easier!

I’ve made a mistake somewhere that I am trying to work out but shouldn’t the second script be?

script:
  brighten_light_landing:

instead of

Or are they both meant to be called dim_light_landing ?

And thank you very much for posting this, it’s too big for me to hold in my head all at once and I never would have been able to do this on my own. Much appreciated.

Hmm nice I guess this would also work for ‘dimming’ the volume of the iTunes component.

1 Like

You’re right, it looks wrong. I will check and update when I’m at a laptop. On mobile at the moment. Thanks!

I have updated now, you were right, should have been brighten. Thanks for pointing out.

I have tried the method with LimitlessLED component, but it doesn’t seem to be working. I can see the brightness increasing and then decreasing from the frontend. But the limitlessLED component is not fast enough. It’s sending commands every half a second or so (from the looks of it). Then the light gradually dims or brightens. I’ve looked into the limitlessled.py component code, but weren’t able to find anything related to repetitions or delays.

1 Like

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: