Skip to content

Commit

Permalink
Add smart dimming and lovelace plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarb committed Jan 22, 2023
1 parent cf82b55 commit ea97710
Show file tree
Hide file tree
Showing 12 changed files with 28,323 additions and 2 deletions.
139 changes: 139 additions & 0 deletions configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ homeassistant:

# Enables the frontend
frontend:
extra_module_url:
- /local/plugins/card-mod.js?v=3.1.1

# Handles redirects from the My Home Assistant service.
my:
Expand Down Expand Up @@ -128,6 +130,17 @@ mqtt:
payload_off: "screenOff"
json_attributes_topic: fully/deviceInfo/#

# Template
template:
- binary_sensor:
- name: IKEA lights
state: >
{{ states.light
| selectattr('object_id', '!=', 'foo')
| selectattr('state', '!=', 'unavailable')
| list
| length
}}
- name: Hallway motion
device_class: motion
Expand Down Expand Up @@ -271,6 +284,24 @@ stream:
# Channge UI config mode
lovelace:
mode: yaml
resources:
- url: /local/plugins/slider-entity-row.js?v=17.2.1
type: module
- url: /local/plugins/fold-entity-row.js?v=2.0.14
type: module
- url: /local/plugins/button-card.js?v=3.4.2
type: module
- url: /local/plugins/homekit-panel-card.js?v=0.6.2
type: module
- url: /local/plugins/slider-button-card.js?v=1.10.3
type: module
- url: /local/plugins/vacuum-card.js?v=2.2.5
type: module
- url: /local/plugins/mini-media-player-bundle.js?v1.15.0
type: module
- url: /local/plugins/auto-entities.js?v1.9.1
type: module


# Text to speech
tts:
Expand Down Expand Up @@ -336,6 +367,114 @@ light:
- light.living_room_ceiling_1
- light.living_room_ceiling_2
- light.living_room_ceiling_3
- platform: group
name: Office lights
entities:
- light.office_top_corner
- light.office_spotlights
- light.office_desk_lamp
- platform: template
lights:
office_lights_smart: &smart_light
friendly_name: "Office lights smart"
unique_id: office_lights_dimming
level_template: >
{{ (expand('group.office')
| map(attribute='attributes.brightness', default=0)
| select("greaterthan", 0)
| list or [0])
| average
| round }}
value_template: >
{{ expand('group.office')
| map(attribute='attributes.brightness', default=0)
| sum > 0 }}
temperature_template: >
{{ ((expand('group.office')
| map(attribute='attributes.color_temp', default=-1)
| select("greaterthan", 0)
| list or [0])| average | round) or Undefined }}
min_mireds_template: >
{{ expand('group.office')
| selectattr('domain', '==', 'light')
| selectattr('attributes.min_mireds')
| map(attribute='attributes.min_mireds')
| list | min | int }}
max_mireds_template: >
{{ expand('group.office')
| selectattr('domain', '==', 'light')
| selectattr('attributes.max_mireds')
| map(attribute='attributes.max_mireds')
| list | max | int }}
turn_on:
service: light.turn_on
target:
entity_id: group.office
turn_off:
service: light.turn_off
target:
entity_id: group.office
set_temperature:
- service: light.turn_on
data:
color_temp: "{{ color_temp }}"
target:
entity_id: >
{{ expand('group.office')
| selectattr('attributes.brightness')
| map(attribute='entity_id')
| list }}
set_level:
# Set brightness by amount to all lights (when all are off), OR only the lights that would remain on by the brightness change
- service: light.turn_on
data:
brightness_step: "{{ brightness - state_attr('light.office_lights_smart', 'brightness')|int }}"
target:
entity_id: >
{% set brightness_from = state_attr('light.office_lights_smart', 'brightness')|int %}
{% set brightness_change = brightness - brightness_from %}
{{ expand("group.office")
| selectattr('attributes.brightness')
| selectattr('attributes.brightness', '>', -brightness_change)
| map(attribute='entity_id')
| list or
expand('group.office')
| selectattr('domain', '==', 'light')
| map(attribute='entity_id')
| list if brightness != 255 else [] }}
# Set brightness to 1 for all lights that would turn off, keeping them on
- service: light.turn_on
data:
brightness_pct: 1
target:
entity_id: >
{% set brightness_from = state_attr('light.office_lights_smart', 'brightness')|int %}
{% set brightness_change = brightness - brightness_from %}
{{ expand('group.office')
| selectattr('attributes.brightness')
| selectattr('attributes.brightness', '<=', -brightness_change)
| map(attribute='entity_id')
| list
}}
# Set brightness to 100 for all lights currently on when slider moves to 100%, or all the lights if all are currently off
- service: light.turn_on
data:
brightness_pct: 100
target:
entity_id: >
{{ expand("group.office")
| selectattr('attributes.brightness')
| map(attribute='entity_id')
| list or
expand('group.office')
| selectattr('domain', '==', 'light')
| map(attribute='entity_id')
| list if brightness == 255 else [] }}
office_smart_lights_v:
<<: *smart_light
friendly_name: "Office lights smart V2"
unique_id: office_lights_dimming_v2

shell_command:
turn_off_computer: ssh {{ ssh_user }} net rpc shutdown -I {{ ip }} -U {{ user }} -t {{ timeout }}
Expand Down
3 changes: 1 addition & 2 deletions groups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ office:
- light.office_spotlights
- light.office_top_corner
- light.office_desk_lamp
- media_player.chromecast_audio

all_lamps:
entities:
Expand All @@ -75,5 +74,5 @@ christmas_lights:
- switch.advent_candlestick
- switch.christmas_tree
- light.living_room_christmas_star
- switch.balcony_string_lights
- switch.balcony_lights
- switch.star
69 changes: 69 additions & 0 deletions scripts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,72 @@ send_robocop_to_waste_bin:
data:
command: app_goto_target
params: !secret waste_bin_location

dim_without_turn_off:
alias: Change brightness in steps without turning lights off
sequence:
- data_template:
brightness: 10
entity_id: "{{ entities | join(', ') }}"
service: light.turn_on

test_script:
alias: For testing purposes
sequence:
- service: system_log.write
data:
message: >
{{ expand(entity_id)
| map(attribute='entity_id')
| list }}
logger: mycomponent.myplatform


smart_dimming_set_level:
alias: Smart dimming of groups with lights in them
sequence:
# Set brightness by amount to all lights (when all are off), OR only the lights that would remain on by the brightness change
- service: light.turn_on
data:
brightness_step: "{{ brightness - state_attr('light.office_lights_smart', 'brightness')|int }}"
target:
entity_id: >
{% set brightness_from = state_attr('light.office_lights_smart', 'brightness')|int %}
{% set brightness_change = brightness - brightness_from %}
{{ expand(entity_id)
| selectattr('attributes.brightness')
| selectattr('attributes.brightness', '>', -brightness_change)
| map(attribute='entity_id')
| list or
expand(entity_id)
| selectattr('domain', '==', 'light')
| map(attribute='entity_id')
| list if brightness != 255 else [] }}
# Set brightness to 1 for all lights that would turn off, keeping them on
- service: light.turn_on
data:
brightness_pct: 1
target:
entity_id: >
{% set brightness_from = state_attr('light.office_lights_smart', 'brightness')|int %}
{% set brightness_change = brightness - brightness_from %}
{{ expand(entity_id)
| selectattr('attributes.brightness')
| selectattr('attributes.brightness', '<=', -brightness_change)
| map(attribute='entity_id')
| list
}}
# Set brightness to 100 for all lights currently on when slider moves to 100%, or all the lights if all are currently off
- service: light.turn_on
data:
brightness_pct: 100
target:
entity_id: >
{{ expand("group.office")
| selectattr('attributes.brightness')
| map(attribute='entity_id')
| list or
expand(entity_id)
| selectattr('domain', '==', 'light')
| map(attribute='entity_id')
| list if brightness == 255 else [] }}
210 changes: 210 additions & 0 deletions www/plugins/auto-entities.js

Large diffs are not rendered by default.

547 changes: 547 additions & 0 deletions www/plugins/button-card.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions www/plugins/card-mod.js

Large diffs are not rendered by default.

101 changes: 101 additions & 0 deletions www/plugins/fold-entity-row.js

Large diffs are not rendered by default.

Loading

0 comments on commit ea97710

Please sign in to comment.