Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify HA automations for adjusting font/font size #17

Merged
merged 1 commit into from
Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion Home_Assistant/packages/plate01/hasp_plate01_00_components.yaml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,42 @@ automation:
- service: input_number.set_value
data:
entity_id: 'input_number.hasp_plate01_activepage'
value: 1
value: 1

script:
##############################################################################
# Selects the font size to best fit the input text
# Required arguments:
# topic: the topic to publish to
# text: the text that should be sized
hasp_plate01_font_size_select:
sequence:
- service: mqtt.publish
data:
topic: "{{topic}}"
payload_template: >
{% set string_length = text)|length %}
{% if string_length <= 6 -%}
3
{% elif (string_length > 6) and (string_length <= 10) %}
2
{% elif (string_length > 10) and (string_length <= 15) %}
1
{% else %}
0
{%- endif %}"

# Updates the message on the specified object making sure that the text fits
# Required arguments:
# objectId: the id of the object on the HASP you want to update, eg: p[2].b[5]
# text: the text that should be sent
hasp_plate01_update_message:
sequence:
- service: script.hasp_plate01_font_size_select
data:
topic: "hasp/plate01/command/{{objectId}}.font"
text: "{{text}}"
- service: mqtt.publish
data:
topic: "hasp/plate01/command/{{objectId}}.txt"
payload_template: "{{text}}"
44 changes: 14 additions & 30 deletions Home_Assistant/packages/plate01/hasp_plate01_p1_scenes.yaml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,22 @@ automation:
topic: 'hasp/plate01/status'
payload: 'ON'
action:
- service: mqtt.publish
- service: script.hasp_plate01_update_message
data:
topic: 'hasp/plate01/command/p[1].b[4].font'
payload: '2'
- service: mqtt.publish
objectId: 'p[1].b[4]'
text: '"Lights On"'
- service: script.hasp_plate01_update_message
data:
topic: 'hasp/plate01/command/p[1].b[4].txt'
payload: '"Lights On"'
- service: mqtt.publish
objectId: 'p[1].b[5]'
text: '"Daylight"'
- service: script.hasp_plate01_update_message
data:
topic: 'hasp/plate01/command/p[1].b[5].font'
payload: '2'
- service: mqtt.publish
objectId: 'p[1].b[6]'
text: '"Night"'
- service: script.hasp_plate01_update_message
data:
topic: 'hasp/plate01/command/p[1].b[5].txt'
payload: '"Daylight"'
- service: mqtt.publish
data:
topic: 'hasp/plate01/command/p[1].b[6].font'
payload: '2'
- service: mqtt.publish
data:
topic: 'hasp/plate01/command/p[1].b[6].txt'
payload: '"Night"'
- service: mqtt.publish
data:
topic: 'hasp/plate01/command/p[1].b[7].font'
payload: '2'
- service: mqtt.publish
data:
topic: 'hasp/plate01/command/p[1].b[7].txt'
payload: '"Lights Off"'
objectId: 'p[1].b[7]'
text: '"Lights Off"'

# Trigger scene.lights_on when p[1].b[4] pressed
- alias: hasp_plate01_p1_SceneButton4
Expand All @@ -51,7 +35,7 @@ automation:
action:
service: scene.turn_on
entity_id: scene.lights_on

# Trigger scene.daylight when p[1].b[5] pressed
- alias: hasp_plate01_p1_SceneButton5
trigger:
Expand Down Expand Up @@ -80,4 +64,4 @@ automation:
payload: 'ON'
action:
service: scene.turn_on
entity_id: scene.lights_off
entity_id: scene.lights_off
38 changes: 13 additions & 25 deletions Home_Assistant/packages/plate01/hasp_plate01_p2_clock.yaml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,14 @@ automation:
topic: 'hasp/plate01/status'
payload: 'ON'
action:
- service: mqtt.publish
- service: script.hasp_plate01_update_message
data:
topic: 'hasp/plate01/command/p[2].b[4].font'
payload: '3'
- service: mqtt.publish
objectId: 'p[2].b[4]'
text: "\"{{(now().strftime('%I')|int)~now().strftime(':%M')}}\""
- service: script.hasp_plate01_update_message
data:
topic: 'hasp/plate01/command/p[2].b[4].txt'
payload_template: "\"{{(now().strftime('%I')|int)~now().strftime(':%M')}}\""
- service: mqtt.publish
data:
topic: 'hasp/plate01/command/p[2].b[5].font'
payload_template: '{% set datelength = (now().strftime("%B ") ~ now().day)|length %}{% if datelength <= 6 -%}3{% elif (datelength > 6) and (datelength <= 10) %}2{% elif (datelength > 10) and (datelength <= 15) %}1{% else %}0{%- endif %}'
- service: mqtt.publish
data:
topic: 'hasp/plate01/command/p[2].b[5].txt'
payload_template: "\"{{now().strftime('%B ') ~ now().day}}\""
objectId: 'p[2].b[5]'
text: "\"{{now().strftime('%B ') ~ now().day}}\""

# Send the current time every minute
- alias: hasp_plate01_p2_ClockUpdate
Expand All @@ -37,11 +29,11 @@ automation:
entity_id: 'binary_sensor.plate01_connected'
state: 'on'
action:
- service: mqtt.publish
- service: script.hasp_plate01_update_message
data:
topic: 'hasp/plate01/command/p[2].b[4].txt'
payload_template: "\"{{(now().strftime('%I')|int)~now().strftime(':%M')}}\""
objectId: 'p[2].b[4]'
text: "\"{{(now().strftime('%I')|int)~now().strftime(':%M')}}\""

# Send "Month Day" every day, scaling font to fit
# 0 consolas 24 - 20 chars x 2 lines (wrapped)
# 1 consolas 32 - 15 chars x 2 lines (wrapped)
Expand All @@ -56,11 +48,7 @@ automation:
entity_id: 'binary_sensor.plate01_connected'
state: 'on'
action:
- service: mqtt.publish
data:
topic: 'hasp/plate01/command/p[2].b[5].font'
payload_template: '{% set datelength = (now().strftime("%B ") ~ now().day)|length %}{% if datelength <= 6 -%}3{% elif (datelength > 6) and (datelength <= 10) %}2{% elif (datelength > 10) and (datelength <= 15) %}1{% else %}0{%- endif %}'
- service: mqtt.publish
- service: script.hasp_plate01_update_message
data:
topic: 'hasp/plate01/command/p[2].b[5].txt'
payload_template: "\"{{now().strftime('%B ') ~ now().day}}\""
objectId: 'p[2].b[5]'
text: "\"{{now().strftime('%B ') ~ now().day}}\""
20 changes: 6 additions & 14 deletions Home_Assistant/packages/plate01/hasp_plate01_p2_weather.yaml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,11 @@ automation:
topic: 'hasp/plate01/status'
payload: 'ON'
action:
- service: mqtt.publish
- service: script.hasp_plate01_update_message
data:
topic: 'hasp/plate01/command/p[2].b[6].font'
payload: '3'
- service: mqtt.publish
objectId: 'p[2].b[6]'
text: '"{{states.sensor.weather_temperature.state}}F"'
- service: script.hasp_plate01_update_message
data:
topic: 'hasp/plate01/command/p[2].b[6].txt'
payload_template: '"{{states.sensor.weather_temperature.state}}F"'
- service: mqtt.publish
data:
topic: 'hasp/plate01/command/p[2].b[7].font'
payload_template: '{% if states.sensor.weather_current.state|length <= 6 -%}3{% elif (states.sensor.weather_current.state|length > 6) and (states.sensor.weather_current.state|length <= 10) %}2{% elif (states.sensor.weather_current.state|length > 10) and (states.sensor.weather_current.state|length <= 15) %}1{% else %}0{%- endif %}'
- service: mqtt.publish
data:
topic: 'hasp/plate01/command/p[2].b[7].txt'
payload_template: '"{{states.sensor.weather_current.state|wordwrap(20, wrapstring="\\r")}}"'
objectId: 'p[2].b[7]'
text: '"{{states.sensor.weather_current.state|wordwrap(20, wrapstring="\\r")}}"'
36 changes: 12 additions & 24 deletions Home_Assistant/packages/plate01/hasp_plate01_p3_toggles.yaml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,18 @@ automation:
topic: 'hasp/plate01/status'
payload: 'ON'
action:
- service: mqtt.publish
data:
topic: 'hasp/plate01/command/p[3].b[4].font'
payload: '2'
- service: mqtt.publish
- service: script.hasp_plate01_update_message
data:
topic: 'hasp/plate01/command/p[3].b[4].txt'
payload: '"Light 1"'
- service: mqtt.publish
objectId: 'p[3].b[4]'
text: '"Light 1"'
- service: script.hasp_plate01_update_message
data:
topic: 'hasp/plate01/command/p[3].b[5].font'
payload: '2'
- service: mqtt.publish
objectId: 'p[3].b[5]'
text: '"Light 2"'
- service: script.hasp_plate01_update_message
data:
topic: 'hasp/plate01/command/p[3].b[5].txt'
payload: '"Light 2"'
- service: mqtt.publish
data:
topic: 'hasp/plate01/command/p[3].b[6].font'
payload: '2'
- service: mqtt.publish
data:
topic: 'hasp/plate01/command/p[3].b[6].txt'
payload: '"Light 3"'
objectId: 'p[3].b[6]'
text: '"Light 3"'
- service: mqtt.publish
data:
topic: 'hasp/plate01/command/p[3].b[7].font'
Expand All @@ -46,7 +34,7 @@ automation:
action:
service: homeassistant.toggle
entity_id: light.light_1

# Toggle light2 when p[3].b[5] pressed
- alias: hasp_plate01_p3_ToggleLight2
trigger:
Expand Down Expand Up @@ -81,7 +69,7 @@ automation:
homeassistant.turn_on
{%- endif %}
entity_id: group.light_toggle_group

# Toggle colors on p[3].b[4] when light1 changes
- alias: hasp_plate01_p3_ToggleColor1
trigger:
Expand Down Expand Up @@ -201,4 +189,4 @@ automation:
"Lights Off"
{%- else -%}
"Lights On"
{%- endif %}
{%- endif %}
32 changes: 16 additions & 16 deletions Home_Assistant/packages/plate01/hasp_plate01_p4_dimmers.yaml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ automation:
topic: 'hasp/plate01/status'
payload: 'ON'
action:
- service: mqtt.publish
- service: script.hasp_plate01_update_message
data:
topic: 'hasp/plate01/command/p[4].b[4].txt'
payload: '"Light 1"'
- service: mqtt.publish
objectId: 'p[4].b[4]'
text: '"Light 1"'
- service: script.hasp_plate01_update_message
data:
topic: 'hasp/plate01/command/p[4].b[5].txt'
payload: '"Light 2"'
- service: mqtt.publish
objectId: 'p[4].b[5]'
text: '"Light 2"'
- service: script.hasp_plate01_update_message
data:
topic: 'hasp/plate01/command/p[4].b[6].txt'
payload: '"Light 3"'
objectId: 'p[4].b[6]'
text: '"Light 3"'

- alias: hasp_plate01_p4_Dimmer7UpdateHass
trigger:
- platform: mqtt
Expand All @@ -29,7 +29,7 @@ automation:
data_template:
entity_id: light.light_1
brightness: '{{ trigger.payload }}'

- alias: hasp_plate01_p4_Dimmer7UpdateHASP
trigger:
- platform: state
Expand All @@ -39,7 +39,7 @@ automation:
data_template:
topic: 'hasp/plate01/command/p[4].b[7].val'
payload_template: '{{states.light.light_1.attributes.brightness|default(0)|int}}'

- alias: hasp_plate01_p4_Dimmer8UpdateHass
trigger:
- platform: mqtt
Expand All @@ -49,7 +49,7 @@ automation:
data_template:
entity_id: light.light_2
brightness: '{{ trigger.payload }}'

- alias: hasp_plate01_p4_Dimmer8UpdateHASP
trigger:
- platform: state
Expand All @@ -59,7 +59,7 @@ automation:
data_template:
topic: 'hasp/plate01/command/p[4].b[8].val'
payload_template: '{{states.light.light_2.attributes.brightness|default(0)|int}}'

- alias: hasp_plate01_p4_Dimmer9UpdateHass
trigger:
- platform: mqtt
Expand All @@ -69,7 +69,7 @@ automation:
data_template:
entity_id: light.light_3
brightness: '{{ trigger.payload }}'

- alias: hasp_plate01_p4_Dimmer9UpdateHASP
trigger:
- platform: state
Expand All @@ -78,4 +78,4 @@ automation:
- service: mqtt.publish
data_template:
topic: 'hasp/plate01/command/p[4].b[9].val'
payload_template: '{{states.light.light_3.attributes.brightness|default(0)|int}}'
payload_template: '{{states.light.light_3.attributes.brightness|default(0)|int}}'
Loading