Skip to content

Commit

Permalink
Merge pull request #23 from rohankapoorcom/improve-color-selection
Browse files Browse the repository at this point in the history
Create a new python script for updating foreground/background colors
  • Loading branch information
aderusha committed Sep 18, 2018
2 parents e093c7d + 6f6127d commit b321dac
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 278 deletions.
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: 19 additions & 25 deletions Home_Assistant/packages/plate01/hasp_plate01_p0_pages.yaml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ automation:
data_template:
entity_id: 'input_number.hasp_plate01_activepage'
value: '{{states.input_number.hasp_plate01_pagebutton1page.state|int}}'

##############################################################################
# select hasp_plate01_pagebutton2page in response to page button 2
- alias: hasp_plate01_p0_PageButton2Action
Expand Down Expand Up @@ -89,7 +89,7 @@ automation:
data_template:
entity_id: 'input_number.hasp_plate01_activepage'
value: '{{states.input_number.hasp_plate01_pagebutton2page.state|int}}'

##############################################################################
# select hasp_plate01_pagebutton3page in response to page button 3
- alias: hasp_plate01_p0_PageButton3Action
Expand Down Expand Up @@ -154,7 +154,7 @@ automation:
data_template:
topic: 'hasp/plate01/command/page'
payload: '{{ states.input_number.hasp_plate01_activepage.state | int }}'

##############################################################################
# Set page button text across all pages to the value selected in the interface

Expand Down Expand Up @@ -312,57 +312,51 @@ automation:
topic: 'hasp/plate01/status'
payload: 'ON'
action:
- service: mqtt.publish
- service: python_script.hasp_update_colors
data_template:
topic: 'hasp/plate01/command/p[{{states.input_number.hasp_plate01_activepage.state|int}}].b[1].bco'
payload_template: >-
nodename: plate01
object_id: 'p[{{states.input_number.hasp_plate01_activepage.state|int}}].b[1]'
background: >-
{% if states.input_number.hasp_plate01_activepage.state|int == states.input_number.hasp_plate01_pagebutton1page.state|int -%}
65535
{%- else -%}
25388
{%- endif %}
- service: mqtt.publish
data_template:
topic: 'hasp/plate01/command/p[{{states.input_number.hasp_plate01_activepage.state|int}}].b[1].pco'
payload_template: >-
foreground: >-
{% if states.input_number.hasp_plate01_activepage.state|int == states.input_number.hasp_plate01_pagebutton1page.state|int -%}
0
{%- else -%}
65535
{%- endif %}
- service: mqtt.publish
- service: python_script.hasp_update_colors
data_template:
topic: 'hasp/plate01/command/p[{{states.input_number.hasp_plate01_activepage.state|int}}].b[2].bco'
payload_template: >-
nodename: plate01
object_id: 'p[{{states.input_number.hasp_plate01_activepage.state|int}}].b[2]'
background: >-
{% if states.input_number.hasp_plate01_activepage.state|int == states.input_number.hasp_plate01_pagebutton2page.state|int -%}
65535
{%- else -%}
25388
{%- endif %}
- service: mqtt.publish
data_template:
topic: 'hasp/plate01/command/p[{{states.input_number.hasp_plate01_activepage.state|int}}].b[2].pco'
payload_template: >-
foreground: >-
{% if states.input_number.hasp_plate01_activepage.state|int == states.input_number.hasp_plate01_pagebutton2page.state|int -%}
0
{%- else -%}
65535
{%- endif %}
- service: mqtt.publish
- service: python_script.hasp_update_colors
data_template:
topic: 'hasp/plate01/command/p[{{states.input_number.hasp_plate01_activepage.state|int}}].b[3].bco'
payload_template: >-
nodename: plate01
object_id: 'p[{{states.input_number.hasp_plate01_activepage.state|int}}].b[3]'
background: >-
{% if states.input_number.hasp_plate01_activepage.state|int == states.input_number.hasp_plate01_pagebutton3page.state|int -%}
65535
{%- else -%}
25388
{%- endif %}
- service: mqtt.publish
data_template:
topic: 'hasp/plate01/command/p[{{states.input_number.hasp_plate01_activepage.state|int}}].b[3].pco'
payload_template: >-
foreground: >-
{% if states.input_number.hasp_plate01_activepage.state|int == states.input_number.hasp_plate01_pagebutton3page.state|int -%}
0
{%- else -%}
65535
{%- endif %}
{%- endif %}
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")}}"'
Loading

0 comments on commit b321dac

Please sign in to comment.