Skip to content

Instantly share code, notes, and snippets.

@dale3h
Created April 6, 2018 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dale3h/342fd95478fa3f7e8246e2e4686dd78b to your computer and use it in GitHub Desktop.
Save dale3h/342fd95478fa3f7e8246e2e4686dd78b to your computer and use it in GitHub Desktop.
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