Thanks for the inspiration :-). I’m wondering if the automation could be made shorter by evaluating the second element of args. I’m using z2m but the basics should be the same: the button reports how much it was “turned”, so if I got it right you are choosing the number of reps/step_pct based on this arg (13, 25, 37 and so on). Maybe something like reps = “round(arg[1]/13)”, should do the trick?
That sounds interesting.
This was a quick and dirty blueprint to make it work.
Nice work, has shown me that i have a lot to get my head around.
My end goal is to get it running as a volume control. Looking over you code as an example i am a step closer.
Thanks for sharing
Hi,
Here’s my take of a automation using this button, but with z2m. The “repeat” part could be used to replace the “while” loop:
- id: botao_rotatorio_1
mode: queued
max_exceeded: silent
trigger:
platform: state
entity_id: sensor.botao_rotatorio_1_action
attribute: action
from: ''
action:
- variables:
action: '{{ trigger.to_state.attributes.action }}'
- choose:
- conditions:
- '{{ action == ''brightness_step_down'' }}'
sequence:
repeat:
count: '{{ (trigger.to_state.attributes.action_step_size / 13) | round }}'
sequence:
- service: <whataver>
- conditions:
- '{{ action == ''brightness_step_up'' }}'
sequence:
repeat:
count: '{{ (trigger.to_state.attributes.action_step_size / 13) | round }}'
sequence:
- service: <whatever>
- conditions:
- '{{ action == ''toggle'' }}'
sequence:
- service: homeassistant.toggle
entity_id: <whatever>
A little bit of explanation: z2m reports the action up/dow + attributes, and immediately after report the actions as “” without all the attributes, like this:
z2mqtt/botao_rotatorio_1 {"action":"brightness_step_down","action_step_size":13,"action_transition_time":0.01,"linkquality":174}
z2mqtt/botao_rotatorio_1 {"action":"","linkquality":174}
z2mqtt/botao_rotatorio_1 {"action":"brightness_step_down","action_step_size":49,"action_transition_time":0.02,"linkquality":174}
z2mqtt/botao_rotatorio_1 {"action":"","linkquality":174}
I am using this product at the moment via z2m and have one in living room that is just a on off button with brightness on rotation and then push and rotate for temprature of lights. In my kids room the other one is on and off button, but with the push and rotate being for cycle through themes, I would be happy to share both automations if you wish so you can try to adapt to this (they both use a couple of scripts to change the temp up and temp down and scene up and scene down). if this helps you make something better. my skill set has not quite got to the all in one automation yet.
This is what I have come up with so far, seems to work but looks like if I assign the single press to toggle a light it will toggle off, pause then back on.
blueprint:
name: Zigbee2MQTT - Tuya Smart Knob TS004F
description: Automate your Tuya Smart Knob (_TZ3000_4fjiwweb) via Zigbee2MQTT.
domain: automation
input:
switch:
name: TS004F Tuya Smart Knob
description: Tuya Smart Knob to use
selector:
entity:
domain: sensor
integration: mqtt
short_press:
name: Single Press
description: Action to run on single press
default: []
selector:
action: {}
double_press:
name: Double Press
description: Action to run on double press
default: []
selector:
action: {}
toggle:
name: Toggle
description: Action to run on Toggle
default: []
selector:
action: {}
hold:
name: Hold
description: Action to run on hold
default: []
selector:
action: {}
rotate_left:
name: Rotate - Left
description: Action to run on left rotation
default: []
selector:
action: {}
rotate_right:
name: Rotate - Right
description: Action to run on right rotation
default: []
selector:
action: {}
brightness_step_up:
name: Brightness Step Up
description: Action to run on right rotation
default: []
selector:
action: {}
brightness_step_down:
name: Brightness Step Down
description: Action to run on left rotation
default: []
selector:
action: {}
color_temperature_step_up:
name: Color Temperature Step Up
description: Action to run on hold & right rotation
default: []
selector:
action: {}
color_temperature_step_down:
name: Color Temperature Step Down
description: Action to run on hold & left rotation
default: []
selector:
action: {}
mode: single
max_exceeded: silent
trigger:
- platform: state
entity_id: !input "switch"
attribute: action
action:
- variables:
command: "{{ trigger.to_state.attributes.action }}"
- choose:
- conditions:
- '{{ command == ''single'' }}'
sequence: !input 'short_press'
- conditions:
- '{{ command == ''double'' }}'
sequence: !input 'double_press'
- conditions:
- '{{ command == ''toggle'' }}'
sequence: !input 'toggle'
- conditions:
- '{{ command == ''rotate_right'' }}'
sequence: !input 'rotate_right'
- conditions:
- '{{ command == ''rotate_left'' }}'
sequence: !input 'rotate_left'
- conditions:
- '{{ command == ''brightness_step_up'' }}'
sequence:
repeat:
count: '{{ (trigger.to_state.attributes.action_step_size / 13) | round }}'
sequence: !input 'brightness_step_up'
- conditions:
- '{{ command == ''brightness_step_down'' }}'
sequence:
repeat:
count: '{{ (trigger.to_state.attributes.action_step_size / 13) | round }}'
sequence: !input 'brightness_step_down'
- conditions:
- '{{ command == ''color_temperature_step_up'' }}'
sequence: !input 'color_temperature_step_up'
- conditions:
- '{{ command == ''color_temperature_step_down'' }}'
sequence: !input 'color_temperature_step_down'
- conditions:
- '{{ command == ''hold'' }}'
sequence: !input 'hold'
for the single press to work, I just set two automations as it worked better, example button press, condition light off, action turn on light, then seperate automation button press, light off, condition light on.
It also allowed me to do it via the call service so I can have all the lights come on and off with a 5 second transition.
using with hue scenes on press and rotate to cycle scenes (you can use with non hue other scenes too)
add a helper, (drop down) give it a name and note the name (mine is input_select.aj_room_scene)
these are all the scenes for that room, when creating this copy over your entities from scenes, just leaving out the scenes. section at the start all my scenes would have scene. from the start of these
the so push in and rotate and clockwise would be used like this (smart dial aj room is my moes rotary)
counter clockwise is this
The important part is the helper and then the actions (color temp step up is the push and rotate action)
the code for the final part of action is
service: scene.turn_on
target:
entity_id: scene.{{ states.input_select.aj_room_scene.state }}
you copy this code and add it and the end edit service as yaml (but obviously replace the input_select.aj_room_scene) with the one you created from your drop down helper
I have to thank @petro here for helping me see my error of leaving scene. at begining of my dropdow helper entries, which was causing the turn on script target scene.scene. lol, hence why you have to make your dropdown helper without scene. at start of each one you add to it.
Does anyone have a blueprint which includes the rotary input? Would be nice to use it for dimming the light.
just set the acton for the “brightness_step_up” trigger of device to do action - device (light name) (increase brightness)?
i see the problem, here if you look previously I did mention I use zigbee2mqtt with mine but it might be dim down buttom pressed for rotate counter clockwise and dim up for clockwise?
This blueprint, the one you are commenting in, does dim-up and dim-down of the light you choose through the rotary input.
@Richi_Bowzer , this doesn’t do anything either:
i added multiple light with decrease brightness to this tigger. Nothing happens if i rotate the smart knob.
Here is the github thread where further support is needed to get all the actions supported by ZHA: https://github.com/zigpy/zha-device-handlers/issues/1268
This is the reason it only supports single press and rotate (without click).
Have you tried it?
The single press can be linked to any action you like.
The rotate function is linked to the light you select.
i don’t understand how this threat helps me getting the rotate function working in ZHA. Did anyone try this?
The rotate function works for me with this blueprint
Can you share a screen shot of your setup?