Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Time and button restricted light control
################################################################
## Packages / Boy's Room Brightness
##
## @description Time and button restricted light control
## @component input_datetime, input_number, light, script
## @license MIT
## @author Dale Higgs <@dale3h>
################################################################
################################################
## Input Datetime
################################################
input_datetime:
boys_room_morning:
name: "Boy's Room Morning"
has_time: true
boys_room_evening:
name: "Boy's Room Evening"
has_time: true
################################################
## Input Number
################################################
input_number:
boys_room_limited_brightness:
name: "Boy's Room Limited Brightness"
min: 1
max: 100
step: 1
################################################
## Script
################################################
script:
boys_room_light:
alias: "Boy's Room Light"
sequence:
- service_template: >-
{% set limited_buttons = ['kids_button'] %}
{% set time = now().strftime('%H.%M')|float %}
{% set morning = states.input_datetime.boys_room_morning.attributes.timestamp|int|timestamp_custom('%H.%M', false)|float %}
{% set evening = states.input_datetime.boys_room_evening.attributes.timestamp|int|timestamp_custom('%H.%M', false)|float %}
{% if (button in limited_buttons and not morning <= time < evening) or is_state('light.boys_room', 'on') %}
script.light_turn_off_proxy
{% else %}
light.turn_on
{% endif %}
data_template:
entity_id: light.boys_room
brightness: >-
{% set time = now().strftime('%H.%M')|float %}
{% set morning = states.input_datetime.boys_room_morning.attributes.timestamp|int|timestamp_custom('%H.%M', false)|float %}
{% set evening = states.input_datetime.boys_room_evening.attributes.timestamp|int|timestamp_custom('%H.%M', false)|float %}
{% if morning < time < evening %}
255
{% else %}
{{ (255 * (states('input_number.boys_room_limited_brightness')|float / 100))|round }}
{% endif %}
light_turn_off_proxy:
alias: "Light Proxy"
sequence:
- service: light.turn_off
data_template:
entity_id: "{{ entity_id }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment