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

AWTRIX does not render integers or numeric sensor data in YAML templates #618

Open
Turtlepaw opened this issue Oct 20, 2024 · 4 comments
Open
Labels
bug Something isn't working

Comments

@Turtlepaw
Copy link

Bug report

Describe the bug

AWTRIX fails to render integer values (such as sensor data) when the output consists solely of a number. However, when appending a non-numeric character (e.g., a space, letter, or symbol), AWTRIX renders the value correctly.

Additional information

  • Devices involved:
    • Model: Ulanzi Awtrix Smart Pixel Clock 2882 (TC001)
    • awtrix3 version: 0.96

To Reproduce

Steps to reproduce the behavior:

  • Set up AWTRIX with a custom sensor app to display step count or other numeric values (e.g., from a Home Assistant sensor).
  • Use a YAML template that outputs an integer value, such as:
text: >
  {% set steps = states('sensor.google_pixel_watch_daily_steps_4') | int %}
  {{ steps }}
  • AWTRIX fails to display anything (blank screen).
  • Modify the template by appending a non-numeric character (e.g., a space, letter, or symbol) to the output, such as:
text: >
  {% set steps = states('sensor.google_pixel_watch_daily_steps_4') | int %}
  {{ steps ~ '*' }}
  • AWTRIX now renders the text (e.g., 5000*).

Expected behavior

AWTRIX should render the integer (e.g., 5000) directly without requiring any additional characters.

Screenshots

awtrix

Logs

No logs

Workaround

Appending an invisible character (like a zero-width space) or a visible symbol to the output forces AWTRIX to display the numeric value.

Example working code:

text: >
  {% set steps = states('sensor.google_pixel_watch_daily_steps_4') | int %}
  {{ steps ~ '​' }}  # Appending zero-width space

Additional context

This bug seems related to how AWTRIX processes or parses numeric values in YAML templates. It treats numeric-only outputs as invalid and doesn’t render them unless a non-numeric character is appended.

@Turtlepaw Turtlepaw added the bug Something isn't working label Oct 20, 2024
@eku
Copy link

eku commented Oct 20, 2024

What does the JSON structure that is sent to Awtrix look like?

@Blueforcer
Copy link
Owner

Blueforcer commented Oct 20, 2024

That's not a Bug.
According to the documentation, you need to send a String in the "text" key, not a number.

So it should be

text: > {% set steps = states('sensor.google_pixel_watch_daily_steps_4') %} {{ steps }}

To make sure it is a string use

text: > {% set steps = states('sensor.google_pixel_watch_daily_steps_4') | string %} {{ steps }}

@Turtlepaw
Copy link
Author

Turtlepaw commented Oct 21, 2024

Hi, @Blueforcer, when using the code you provided:

text: >
  {% set steps = states('sensor.google_pixel_watch_daily_steps_4') | string %}
  {{ steps }}

It still fails to render the text.

📸 Awtrix Image

awtrix (1)

🤖 Home Assistant Automation

This automation uses a third-party library: 10der/homeassistant-custom_components-awtrix

alias: Awtrix Steps
description: ""
triggers:
  - trigger: state
    entity_id:
      - sensor.google_pixel_watch_daily_steps_4
  - trigger: time_pattern
    minutes: "14"
conditions: []
actions:
  - action: awtrix.awtrix_2d8db4_push_app_data
    data:
      name: Steps
      data:
        text: >
          {% set steps = states('sensor.google_pixel_watch_daily_steps_4') |
          string %}  {{ steps }}
        icon: "30415"
        duration: 0
        pushIcon: 0
        lifetime: 900
        repeat: 1
mode: single

@Honusnap
Copy link

The problem is most certainly caused by the way the text is sent to the publish order, it's lost somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants