Tradfri dimmer automation
Could someone post his/hers tradfri dimmer automation? I have an automation but this one won't turn off the lights at brightness 0.
- alias: Tradfri Dimmer WZ
initial_state: 'on'
trigger:
platform: state
entity_id: sensor.zigbee_dimmer_wz
action:
- service: light.turn_on
data_template:
entity_id: sensor.zigbee_dimmer_wz
brightness: '{{ state.sensor.zigbee_dimmer_wz.state }}'
Do you know how to get the old dimmer value? Or how to save the old one?
Shouldn't states.sensor.dimmer_01_brightness.states still have the old value while executing?
Else make a hidden input that stores the old value after each run. see https://www.home-assistant.io/components/input_number/
maybe @Petro31 could help with that question.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Stay open
I asked for https://github.com/Koenkk/zigbee2mqtt/issues/1191 - Makes automations way easyer.
@WagnerBeccard could you show your automation?
Hi. The entire project is supercool, so I want to contribute too - at least with my idea how to make good responsive brightness control for IKEA dimmer. I have migrated to AppDaemon, so do not have my old .yaml for the automations - but my logic worked with .yaml too. Yes #1191 indeed was a great feature. The main trick I used is I calculated milliseconds between rotation start and rotation stop. My logic:
- as soon as dimmer rotation starts, automations triggers slow transition from current brightness in either direction (up or down)
- time for this transition is caclucated based on current position and direction till 0 or 100 %
- as soon as rotation stops i get milliseconds difference and calculate what should be exact brigtness to set
- this exact brightness is sent to the bulb and this also stops slow trinsition
So it give really good responsive control over when to stop rotation (as soon as you are satisfied with the current level of brigtness you see with you own eyes). I think this logic is even better then factory logic which is glitchy and jumps from one level of brightness to another.
@sergiigladchuk are you also able to handle this situation somehow?
Light is one because you turned it on by voice Dimmer value = 0 Turn dimmer to the left because you want to dimm down, which means going from 0 to 0
Same thing for 100%
- alias: ikeadimmer_lights
initial_state: on
trigger:
platform: mqtt
topic: 'zigbee2mqtt/kueche_ikea'
condition:
condition: or
conditions:
- condition: template
value_template: "{{ 'rotate_right_quick' == trigger.payload_json.action }}"
- condition: template
value_template: "{{ 'rotate_left_quick' == trigger.payload_json.action }}"
- condition: template
value_template: "{{ 'rotate_stop' == trigger.payload_json.action }}"
action:
- service: light.turn_on
data_template:
entity_id: light.nachttisch
brightness: "{{ trigger.payload_json.brightness }}"
transition: 1
- wait_template: "{{ trigger.payload_json.brightness == '0' }}"
timeout: '00:00:01'
continue_on_timeout: 'false'
- service: light.turn_off
entity_id: light.nachttisch
only issue I have. sometimes that messages getting in too quick. then the coordinator getting clogged up and needs up to 20 secconds to react.
@sergiigladchuk are you also able to handle this situation somehow?
Light is one because you turned it on by voice Dimmer value = 0 Turn dimmer to the left because you want to dimm down, which means going from 0 to 0
Same thing for 100%
Just use MIN and MAX (for directions up and down respectively) in order to keep resulting brightnes_pct from 0 to 100. Here is few lines from my script in AppDaemon :
if self.direction == 'up':
self.br_pct = min([self.br_pct + int(elapsed / 1000 / self.args['transition_sec'] * 100), 100])
else:
self.br_pct = max([self.br_pct - int(elapsed / 1000 / self.args['transition_sec'] * 100), 1])
where br_pct is updated based on elapsed milliseconds. So if you have brightness on 0, and rotate the dimmer further it will stay 0.
One important thing I have not mentioned in my initial post - I do not care at all about brightness reported by the dimmer. You can either read brightness directly from the lamp or keep it in separate input_number (as I do). So I only care about rotations reported by the dimmer, and elapsed time between start and stop of the rotation.
@WagnerBeccard you can simplify your condition, just check if the payload contains 'action'
- alias: 'Ikea Dimmer Bad'
trigger:
- platform: mqtt
topic: 'zigbee2mqtt/0x000b57fffe150d50'
condition:
- condition: template
value_template: "{{ 'action' in trigger.payload }}"
action:
- service: light.turn_on
data_template:
entity_id: light.ikea_bad
brightness: '{{ trigger.payload_json.brightness }}'
also you can remove that wait > turn_off since recently turn_on with 0 brightness turns the lamp off.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@sergiigladchuk thanks for your idea of counting milliseconds between start and stop, and starting transition when rotation starts. I think that's the only way of getting it to work nicely.