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
light.YOURLIGHT with your light.entity_id
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
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
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!
Hi there, can some one help me with this? I’m not able to dim the light, it work only one time…
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?!
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. 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
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.
Finally got around to trying this out tonight. Really great piece of script - Thank you so much!
I’m using it with MiLights atm, so the lights dim/brighten very slowly, but it works. Looking forward to trying this with my zwave dimmers soon.
I’ve also added my own bit of automation:
Single Click - toggle light on/off
Double Click - Jump to Max Brightness (and turn on boolean - ready to dim)
automation:
- alias: xiaomi Click to toggle Light
initial_state: 'on'
trigger:
- platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d0001XXXXXX
click_type: single
action:
- service: light.toggle
entity_id: light.XXXXXX
- alias: xiaomi Double Click to Max Brightness
trigger:
platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d0001XXXXXX
click_type: double
action:
- service: light.turn_on
entity_id: light.XXXXXX
data:
brightness: 250 #for some reason 255 did not work for me
- service: input_boolean.turn_off
entity_id: input_boolean.landing_dim
Any cheap lights that work well in this configuration?
Yeelight RGB bulbs work ok with this and they are quite cheap I think
Glad to see this is getting some use!
Anyone got a neat mounting solution for the gen1 round button they can share?
Also, what is everyone using to communicate with button? Xiaomi GW or Zigbee receiver (if so, what are you using?)
Thanks and I hope this automation is still useful to people out there