Skip to content

Instantly share code, notes, and snippets.

@QNimbus
Last active June 25, 2024 14:12
Show Gist options
  • Save QNimbus/7db1fad83b34d2be52ceebcbb3ec74a5 to your computer and use it in GitHub Desktop.
Save QNimbus/7db1fad83b34d2be52ceebcbb3ec74a5 to your computer and use it in GitHub Desktop.
Home Assistant #ha
# Blueprint metadata
blueprint:
name: Disable Fibaro lights during daylight
description: |
# 🪄 Disable Fibaro lights during daylight
**Version: 0.3**
This blueprint can disable the manual operation of one or more Fibaro dimmers during a certain period (i.e. daytime, between sunrise and sunset).
The use case for this blueprint is the fact that my children occasionally refuse to open their bedroom curtains and switch on their room lights during the day which is wasteful and not required when the sun is up.
Using this blueprint/automation the manual operation of these lights is inhibited during daytime.
<details>
<summary><b>The Automation Process:</b> - Click here to expand</summary>
</details>
Required = *
GitHub: [Click Here](https://gist.githubusercontent.com/QNimbus/7db1fad83b34d2be52ceebcbb3ec74a5/raw/blueprints---fibaro_daylight_disable.yaml)
domain: automation
source_url: https://gist.githubusercontent.com/QNimbus/7db1fad83b34d2be52ceebcbb3ec74a5/raw/blueprints---fibaro_daylight_disable.yaml
input:
switch_off_lights:
name: " Switch off lights?"
description: >-
Also turn off the light(s) if they were on.
selector:
boolean:
fibaro_devices:
name: " Fibaro dimmer(s)"
description: >-
Which Fibaro dimmer(s) do you want to control?
<details>
<summary><code><strong>[ More info ]</strong></code></summary>
Select one or more Fibaro dimmers that you want to disable manual/local control for during the daylight period.
</details>
selector:
device:
multiple: true
filter:
- integration: zwave_js
manufacturer: Fibargroup
model: FGD212
sun_elevation:
name: "Sun Elevation"
description: "Set the sun elevation value above which local operation should be disabled."
default: 6.0
selector:
number:
min: -10
max: 20
step: 0.1
unit_of_measurement: "°"
manual_control:
name: "Re-enable manual control on manual trigger of automation"
description: "Re-enable manual control when the automation is manually triggered regardless of sun elevation."
default: false
selector:
boolean:
mode: restart
max_exceeded: silent
variables:
switch_off_lights: !input switch_off_lights
fibaro_devices: !input fibaro_devices
sun_elevation: !input sun_elevation
manual_control: !input manual_control
fibaro_entities: >-
{%- set ns = namespace(fibaro_entities=[]) -%}
{%- for device in fibaro_devices -%}
{%- for entity in device_entities(device) -%}
{%- if entity | regex_search("^select\\..*local.*$") -%}
{%- set ns.fibaro_entities = ns.fibaro_entities + [entity] -%}
{%- endif -%}
{%- endfor -%}
{%- endfor -%}
{{ ns.fibaro_entities }}
trigger:
- platform: numeric_state
entity_id: sun.sun
attribute: elevation
above: !input sun_elevation
id: "t1_start"
- platform: numeric_state
entity_id: sun.sun
attribute: elevation
below: !input sun_elevation
id: "t1_end"
- platform: homeassistant
id: "homeassistant_start"
event: start
# All Conditions
condition: []
# Actions
action:
- alias: "Determine if manually triggered"
choose:
- conditions:
- condition: template
value_template: "{{ trigger.platform != 'numeric_state' and trigger.platform != 'homeassistant' }}"
sequence:
- alias: "Handle manual trigger if allowed"
choose:
- conditions:
- "{{ manual_control }}"
sequence:
- service: select.select_option
data:
option: Unprotected
target:
entity_id: "{{ fibaro_entities }}"
- conditions:
- condition: numeric_state
entity_id: sun.sun
attribute: elevation
above: !input sun_elevation
sequence:
- alias: "Disable local operation after sunrise"
service: select.select_option
data:
option: NoOperationPossible
target:
entity_id: "{{ fibaro_entities }}"
- choose:
- conditions:
- condition: template
value_template: "{{ switch_off_lights }}"
sequence:
- service: light.turn_off
target:
device_id: !input fibaro_devices
- conditions:
- condition: numeric_state
entity_id: sun.sun
attribute: elevation
below: !input sun_elevation
sequence:
- alias: "Enable local operation before sunrise"
service: select.select_option
data:
option: Unprotected
target:
entity_id: "{{ fibaro_entities }}"
- service: light.turn_off
target:
device_id: !input fibaro_devices
# Blueprint metadata
blueprint:
name: Friends of Hue switch
description: >
HA version 2023.08 or newer
When using the Friends of Hue switch using the zigbee2mqtt integration, the switch is not recognized as a button. This blueprint allows you to use the Friends of Hue switch as a button. The blueprint supports short press, long press, double press, and press and hold actions.
Requirements:
- Friends of Hue switch
- zigbee2mqtt integration
- HA version 2023.08 or newer
- binary_sensor entities for each button on the Friends of Hue switch
e.g. for a Friends of Hue switch with 4 buttons, you need 4 binary_sensor entities.
```yaml
mqtt:
binary_sensor:
- name: "Friends of Hue Smart Switch 01 - Button A0"
unique_id: 76258bd9-61be-4069-83ee-45c2747ea960
icon: mdi:grid-large
state_topic: "zigbee2mqtt/FriendsOfHueSmartSwitch01/action"
payload_on: "press_1"
payload_off: "release_1"
```
GitHub: [Click Here](https://gist.githubusercontent.com/QNimbus/7db1fad83b34d2be52ceebcbb3ec74a5/raw/blueprints---hue_switch.yaml)
domain: automation
source_url: https://gist.githubusercontent.com/QNimbus/7db1fad83b34d2be52ceebcbb3ec74a5/raw/blueprints---hue_switch.yaml
input:
hue-double-press-time:
name: "Double press time span"
description: "Maximal time between two button presses to count as double press"
selector:
entity:
domain: input_number
hue-switch-button1:
name: "Button 1 (A0)"
description: "Upper left"
selector:
entity:
filter:
domain: binary_sensor
hue-switch-button2:
name: "Button 2 (A1)"
description: "Lower left"
selector:
entity:
device_class: binary_sensor
multiple: false
hue-switch-button3:
name: "Button 3 (B0)"
description: "Upper right"
selector:
entity:
device_class: binary_sensor
multiple: false
hue-switch-button4:
name: "Button 4 (B1)"
description: "Lower right"
selector:
entity:
device_class: binary_sensor
multiple: false
button_1_short_release:
name: Short Release 1
description: Action to run on button upper-left short release
default: []
selector:
action: {}
button_2_short_release:
name: Short Release 2
description: Action to run on button lower-left short release
default: []
selector:
action: {}
button_3_short_release:
name: Short Release 3
description: Action to run on button upper-right short release
default: []
selector:
action: {}
button_4_short_release:
name: Short Release 4
description: Action to run on button lower-right short release
default: []
selector:
action: {}
button_1_long_release:
name: Long Release 1
description: Action to run on button upper-left long release
default: []
selector:
action: {}
button_2_long_release:
name: Long Release 2
description: Action to run on button lower-left long release
default: []
selector:
action: {}
button_3_long_release:
name: Long Release 3
description: Action to run on button upper-right long release
default: []
selector:
action: {}
button_4_long_release:
name: Long Release 4
description: Action to run on button lower-right long release
default: []
selector:
action: {}
button_1_press:
name: Press 1
description: Action to run on button upper-left initial press
default: []
selector:
action: {}
button_2_press:
name: Press 2
description: Action to run on button lower-left initial press
default: []
selector:
action: {}
button_3_press:
name: Press 3
description: Action to run on button upper-right initial press
default: []
selector:
action: {}
button_4_press:
name: Press 4
description: Action to run on button lower-right initial press
default: []
selector:
action: {}
button_1_double_press:
name: Double Press 1
description: Action to run on button upper-left initial double press
default: []
selector:
action: {}
button_2_double_press:
name: Double Press 2
description: Action to run on button lower-left initial double press
default: []
selector:
action: {}
button_3_double_press:
name: Double Press 3
description: Action to run on button upper-right initial double press
default: []
selector:
action: {}
button_4_double_press:
name: Double Press 4
description: Action to run on button lower-right initial double press
default: []
selector:
action: {}
button_1_repeat:
name: Repeat 1
description: Action to run on button upper-left repeat
default: []
selector:
action: {}
button_2_repeat:
name: Repeat 2
description: Action to run on button lower-left repeat
default: []
selector:
action: {}
button_3_repeat:
name: Repeat 3
description: Action to run on button upper-right repeat
default: []
selector:
action: {}
button_4_repeat:
name: Repeat 4
description: Action to run on button lower-right repeat
default: []
selector:
action: {}
# Automation schema
mode: queued
max: 10
trigger:
- platform: state
entity_id: !input "hue-switch-button1"
id: A0
- platform: state
entity_id: !input "hue-switch-button2"
id: A1
- platform: state
entity_id: !input "hue-switch-button3"
id: B0
- platform: state
entity_id: !input "hue-switch-button4"
id: B1
action:
- variables:
switch_to_state: "{{ trigger.to_state.attributes.event_type }}"
switch_from_state: "{{ trigger.from_state.attributes.event_type }}"
switch_id: "{{ trigger.id }}"
hue_double_press_seconds: !input "hue-double-press-time"
# switch_from_ID: '{{ trigger.entity_id }}'
- choose:
- conditions: "{{ switch_to_state == 'initial_press' }}"
sequence:
- choose:
- conditions: "{{ switch_id == 'A0' }}"
sequence:
- if: { condition: template, value_template: "{{ true }}" }
then: !input "button_1_press"
- wait_for_trigger:
- platform: state
entity_id: !input "hue-switch-button1"
timeout:
seconds: "{{ states('hue_double_press_time') | int }}"
continue_on_timeout: false
- if: { condition: template, value_template: "{{ true }}" }
then: !input "button_1_double_press"
- conditions: "{{ switch_id == 'A1' }}"
sequence:
- if: { condition: template, value_template: "{{ true }}" }
then: !input "button_2_press"
- wait_for_trigger:
- platform: state
entity_id: !input "hue-switch-button2"
timeout:
seconds: 2
continue_on_timeout: false
- if: { condition: template, value_template: "{{ true }}" }
then: !input "button_2_double_press"
- conditions: "{{ switch_id == 'B3' }}"
sequence:
- if: { condition: template, value_template: "{{ true }}" }
then: !input "button_3_press"
- wait_for_trigger:
- platform: state
entity_id: !input "hue-switch-button3"
timeout:
seconds: 2
continue_on_timeout: false
- if: { condition: template, value_template: "{{ true }}" }
then: !input "button_3_double_press"
- conditions: "{{ switch_id == 'B4' }}"
sequence:
- if: { condition: template, value_template: "{{ true }}" }
then: !input "button_4_press"
- wait_for_trigger:
- platform: state
entity_id: !input "hue-switch-button4"
timeout:
seconds: 2
continue_on_timeout: false
- if: { condition: template, value_template: "{{ true }}" }
then: !input "button_4_double_press"
- conditions: "{{ switch_to_state == 'repeat' }}"
sequence:
- choose:
- conditions: "{{ switch_id == 'B1' }}"
sequence: !input "button_1_repeat"
- conditions: "{{ switch_id == 'B2' }}"
sequence: !input "button_2_repeat"
- conditions: "{{ switch_id == 'B3' }}"
sequence: !input "button_3_repeat"
- conditions: "{{ switch_id == 'B4' }}"
sequence: !input "button_4_repeat"
- conditions: "{{ switch_to_state == 'long_release' }}"
sequence:
- choose:
- conditions: "{{ switch_id == 'B1' }}"
sequence: !input "button_1_long_release"
- conditions: "{{ switch_id == 'B2' }}"
sequence: !input "button_2_long_release"
- conditions: "{{ switch_id == 'B3' }}"
sequence: !input "button_3_long_release"
- conditions: "{{ switch_id == 'B4' }}"
sequence: !input "button_4_long_release"
- conditions: "{{ switch_to_state == 'short_release' }}"
sequence:
- choose:
- conditions: "{{ switch_from_state == 'initial_press' }}"
sequence:
- choose:
- conditions: "{{ switch_id == 'B1' }}"
sequence: !input "button_1_short_release"
- conditions: "{{ switch_id == 'B2' }}"
sequence: !input "button_2_short_release"
- conditions: "{{ switch_id == 'B3' }}"
sequence: !input "button_3_short_release"
- conditions: "{{ switch_id == 'B4' }}"
sequence: !input "button_4_short_release"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment