Skip to content

Instantly share code, notes, and snippets.

@SirGoodenough
Last active December 13, 2024 17:27
Show Gist options
  • Save SirGoodenough/9b3731ed6d30813aee15925f92dca8f4 to your computer and use it in GitHub Desktop.
Save SirGoodenough/9b3731ed6d30813aee15925f92dca8f4 to your computer and use it in GitHub Desktop.
Automations attached to my Youtube Episode 124 https://whatarewefixing.today/1797/tuya-lights-in-home-assistant/
### The All Off Toggle I did in the video:
- id: '1729450027538'
alias: Toggle Basement Middle area
description: On and off the 4 basement light middle area
triggers:
- trigger: state
entity_id:
- light.see_basement_switch_switch_3
conditions: []
actions:
- action: light.toggle
target:
entity_id:
- light.smart_bulb
- light.smart_bulb_2
- light.smart_bulb_3
- light.see_basement_switch_switch_1
data: {}
mode: single
#### The new and improved all off that won't get confused by lights in random states...
- id: 3e314457-df09-4984-ad90-f81b1395fadb
alias: Toggle Middle area
description: >
### On and off the 4 Basement Lights Middle Area
This is designed so it doesn't care the current status of the lights.
It will make the lights follow the state of the switch.
It requires a awitch or light or toggle that can be turned on and off.
triggers:
- trigger: state
entity_id:
- light.see_basement_switch_switch_2
variables:
lights:
- light.smart_bulb
- light.smart_bulb_2
- light.smart_bulb_3
- light.see_basement_switch_switch_1
state: '{{ trigger.to_state.state }}'
actn: '{{ "light.turn_" ~ state }}'
actions:
- action: '{{ actn }}'
target:
entity_id: '{{ lights }}'
mode: queued
#### The button 3 automation set that turns on lights in dofferent sequences.
#### One to read the button to cycle the counter.
#### One to change the state of the lights based onb the counter number.
- id: 91e94538-ba65-492e-8852-9896dc846be5
alias: Cottage Round-Robin Lights Incrementer
description: >
### Cottage Round-Robin Lights Incrementer
This automation will watch a switch and treat it like a button.
If this switch is pressed, it will immediately turn it back off to reset it for
another press.
These presses are then counted thru a incemeental counter to resut in populating
an input_number with the value 0 thru 7.
At 7 another button press will result in 0.
This is used in cooperation with the "Cottage Round-Robin Lights Actioner"
automation to control 3 lights.
To use this as your own:
* Change the light in "sw1:" and the "trigger entity_id:" below
to match the name of your device. An light was used for testing,
but you might have a switch ot something else in there.
The device needs to report off and on and stay in that state.
if the device reports something else adjust the trigger to match the device.
* Change the input_number name in variables: "innum:" below to match yours.
Input_number parameters min:0, max:7, step 1, hidden.
triggers:
- alias: Trigger when the switch (sw1) is clicked
trigger: state
entity_id: light.see_basement_switch_switch_3
from: 'off'
to: 'on'
variables:
sw1: light.see_basement_switch_switch_3
innum: input_number.middle_lights_sequencer
innum_reset: "{{ states( innum ) | int > 6 }}"
actions:
- alias: Reset the switch to ready for another click
action: light.turn_off
target:
entity_id: "{{ sw1 }}"
data: {}
- if: "{{ innum_reset }}"
then:
- alias: This click reset it to 0
action: input_number.set_value
data:
value: 0
target:
entity_id: "{{ innum }}"
else:
- alias: This click increment the number
action: input_number.increment
target:
entity_id: "{{ innum }}"
data: {}
mode: single
- id: ca4fe8eb-aa96-44fc-b029-a0cab1a17a19
alias: Cottage Round-Robin Lights Actioner
description: >
### Cottage Round-Robin Lights Actioner
Change the state of the lights based on the incrementer control number
The "innum:" number will be 0-7. 000 - 111 in binary 7. I have assigned each
of these 3 binary bits to one of the lights.
What happens is as the number increments, the lights come on when the binary bit
in the input number comes on.
Here is the table:
```text
Control light1 light2 light3
0 OFF OFF OFF
1 ON OFF OFF
2 OFF ON OFF
3 ON ON OFF
4 OFF OFF ON
5 ON OFF ON
6 ON ON OFF
7 ON ON ON
```
To use this as your own:
* Change the 3 light variables: (light1:, light2:, light3:) below to match
the lights you would like to control.
* Change the input_number name in variables: "innum:" and the
"trigger: entity_id:" places below to match yours.
Input_number parameters min:0, max:7, step 1, hidden.
triggers:
- alias: The control number has changed
trigger: state
entity_id: input_number.middle_lights_sequencer
variables:
light1: light.smart_bulb
light2: light.smart_bulb_2
light3: light.smart_bulb_3
innum: input_number.middle_lights_sequencer
innum_val: "{{ states( innum ) | int }}"
l1_on: >
{% if innum_val | bitwise_and(1) == 1 -%}
on
{%- else -%}
off
{%- endif %}
l1_actn: '{{ "light.turn_" ~ l1_on }}'
l2_on: >
{% if innum_val | bitwise_and(2) == 2 -%}
on
{%- else -%}
off
{%- endif %}
l2_actn: '{{ "light.turn_" ~ l2_on }}'
l3_on: >
{% if innum_val | bitwise_and(4) == 4 -%}
on
{%- else -%}
off
{%- endif %}
l3_actn: '{{ "light.turn_" ~ l3_on }}'
actions:
- parallel:
- alias: Set light1
action: '{{ l1_actn }}'
target:
entity_id: '{{ light1 }}'
- alias: Set light2
action: '{{ l2_actn }}'
target:
entity_id: '{{ light2 }}'
- alias: Set light3
action: '{{ l3_actn }}'
target:
entity_id: '{{ light3 }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment