@culloden_spectre wrote:
I have a Xiaomi Zigbee button in each of my rooms (sometimes several per) and these buttons control the Lifx lights in that room.
All the buttons around the house work the same, makes things easy for all members of the house and guests.
1 press - Toggle Light
2 press - Toggle between 50% and 100% brightness
Press & Hold - turn on lights to 13% brightnessThis works fantastic, but, if i want to make a change to any of the automaitions e.g. change the brightness levels when you hold the button, I have to do it to ALL the automations i have written, as consistency is key between the rooms, this is a very lengthy process that is prone to human error.
I have a little bit of experience in Arduino and C++, so i was wondering if it’s possible to create a “function” when i can pass the “switch event” (1 press, 2 press, Hold), the “switch name” and the “light names” into the function to process and execute the desired command.
This way there is effectively only one automation code (the function) which is easy to maintain, change, and easy to scale up when I buy more lights/buttons.
For example (very rough pseudocode)
Event yaml:- alias: Lights Living Room trigger: platform: event event_type: xiaomi_aqara.click event_data: entity_id: binary_sensor.switch_0001 action: - alias: '' data: service: Xiaomi_Switch(click.type, binary_sensor.switch_0001, light.living_room_lights)
Automation Function:
Xiaomi_Switch(switch.event, switch.name, light.name){ if( switch.event == "1 press"){ Toggle light.name } if( switch.event == "2 press"){ service: light.turn_on data_template: entity_id: light.name brightness: "{% if states.light.name.attributes.brightness <\ \ 254 %}\n 254\n{% elif states.light.name.attributes.brightness\ \ > 250 %}\n 130\n{% endif %}\n" } if( switch.event == "Press & Hold"){ turn on light.name Brightness = 13 } }
If i have to create a function for each event type, i can live with it.
So… is what im trying to achieve possible?
Thank you!
Posts: 5
Participants: 4