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

Conversation

rohankapoorcom
Copy link
Contributor

@rohankapoorcom rohankapoorcom commented Aug 22, 2018

Hey @aderusha,

I noticed that most of the time when HA is updating the text for a specific object on the HASP, it has to recompute the font size and send that as well. I created a couple of scripts to:

  • generalize the computation of the font size
  • generalize the object update text by first calling the previous script and then publishing the text update to MQTT

This simplifies the number of operations that have to be done in an individual automation by half, improving readability and removing copying/pasting of values.

Here's an example:

Before:

    - 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")}}"' 

After:

    - service: script.hasp_plate01_update_message
      data:
        objectId: 'p[2].b[7]'
        text: '"{{states.sensor.weather_current.state|wordwrap(20, wrapstring="\\r")}}"'

@aderusha
Copy link
Owner

HOLY COW this is amazing. I'm on the road this week which is going to result in a little more time required for me to test all of this but I FRICKEN LOVE IT and it simplifies a lot of things. I didn't know scripts worked this way! Thanks @rohankapoorcom, I'll push to get this all rolled into my test environment ASAP and then merge this fantastic work into the project.

@rohankapoorcom
Copy link
Contributor Author

Let me know if you run into any problems, or if I missed any spots. I extracted and and generalized this functionality from my environment (which was tested) but (my environment) also contains many other changes related to this stuff.

@aderusha aderusha changed the base branch from master to dev August 22, 2018 19:33
@aderusha aderusha merged commit 5f4c92a into aderusha:dev Aug 22, 2018
@rohankapoorcom rohankapoorcom deleted the improve-font-size-selection branch August 24, 2018 05:30
@rohankapoorcom
Copy link
Contributor Author

@aderusha I've discovered a few bugs with this current approach:

  1. First of all there are a few typos when I migrated things from my repo to this generic version
  2. HA doesn't allow scripts to get called in parallel so this approach leads to a lot of dropped messages being sent to the HASP and a mess of warning messages in the logs. The solution according to this post is a python script. I'll refactor with that and update this (hopefully tomorrow).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants