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

Template not working properly #50

Open
kylewilliams321 opened this issue Nov 17, 2022 · 13 comments
Open

Template not working properly #50

kylewilliams321 opened this issue Nov 17, 2022 · 13 comments
Assignees
Labels
bug Something isn't working

Comments

@kylewilliams321
Copy link

Not sure if I'm doing something wrong but I've tried copy/pasting the yaml custom lovelace template in and it doesn't appear to work correctly. I've obviously tried changing the peloton username to my own but still nothing.

The one thing I've noticed is that I'm not sure if maybe something changed in the way the sensors/attributes are grouped together in the entities. Each "Sensor" appears to be its own entity and maybe before this wasn't the case?

I've tried each of the following setups without any success:
state_attr('sensor.Sir_Farts_A_Lot', "Speed Max Mph") | float | round(2) }} max
state_attr('sensor.kyle_on_peloton_speed_max', "Speed Max Mph") | float | round(2) }} max
state_attr('sensor.kyle_on_peloton', "Speed Max Mph") | float | round(2) }} max

My username is "Sir_Farts_A_Lot" but my sensors all show up as "kyle_on_peloton". Is my setup just wrong or is something else going on here?

Screenshot_11172022

Here's my yaml that isn't working:

type: markdown
content: >+
{% if state_attr('sensor.kyle_on_peloton', "Resistance %") | float > 0 -%}

Current Metrics:

Heart Rate (bpm): {{ state_attr('sensor.kyle_on_peloton', "Heart Rate Bpm") }}
Resistance (%): {{ state_attr('sensor.kyle_on_peloton', "Resistance %") }}
Speed (Mph): {{ state_attr('sensor.kyle_on_peloton', "Speed Mph") }}
Speed (Kph): {{ state_attr('sensor.kyle_on_peloton', "Speed Kph") }}
Cadence Rpm: {{ state_attr('sensor.kyle_on_peloton', "Cadence Rpm") }}
Power (W): {{ state_attr('sensor.kyle_on_peloton', "Power W") }}


{%- endif %}

Latest Workout Summary:

- Date: {{ state_attr('sensor.kyle_on_peloton', "Start Time")|float|timestamp_custom('%Y/%m/%d » %H:%M') }} - {{ state_attr('sensor.kyle_on_peloton', "End Time")|float|timestamp_custom('%H:%M') }} ({{ state_attr('sensor.kyle_on_peloton', "Duration Min") }} mins)

{% if (state_attr('sensor.kyle_on_peloton', 'Workout Image')|string != 'None') %}
<img src="{{ state_attr('sensor.kyle_on_peloton', "Workout Image") }}">
{% endif %}

{{ state_attr('sensor.kyle_on_peloton', "Ride Title") }} ({{ state_attr('sensor.kyle_on_peloton', "Workout Type") }})

  • {{ state_attr('sensor.kyle_on_peloton', "Description") }}
  • Instructor: {{ state_attr('sensor.kyle_on_peloton', "Instructor") }}

Latest Workout Metrics:

- Distance (Mi): {{ state_attr('sensor.kyle_on_peloton', "Distance Mi") | float | round(2) }}
- Heart Rate (bpm): {{ state_attr('sensor.kyle_on_peloton', "Heart Rate Average Bpm") | float | round(0) }} avg / {{ state_attr('sensor.kyle_on_peloton', "Heart Rate Max Bpm") | float | round(0) }} max
- Resistance: {{ state_attr('sensor.kyle_on_peloton', "Resistance Average %") | float | round(0) }}% avg / {{ state_attr('sensor.kyle_on_peloton', "Resistance Max %") | float | round(0) }}% max
- Speed (Mph): {{ state_attr('sensor.kyle_on_peloton', "Speed Average Mph") | float | round(2) }} avg / {{ state_attr('sensor.kyle_on_peloton', "Speed Max Mph") | float | round(2) }} max
- Speed (Kph): {{ state_attr('sensor.kyle_on_peloton', "Speed Average Kph") | float | round(2) }} avg / {{ state_attr('sensor.kyle_on_peloton', "Speed Max Kph") | float | round(2) }} max
- Cadence (Rpm): {{ state_attr('sensor.kyle_on_peloton', "Cadence Average Rpm") | float | round(0) }} avg / {{ state_attr('sensor.kyle_on_peloton', "Cadence Max Rpm") | float | round(0) }} max
- Power (W): {{ state_attr('sensor.kyle_on_peloton', "Power Average W") | float | round(2) }} avg / {{ state_attr('sensor.kyle_on_peloton', "Power Max W") | float | round(2) }} max
- Total Work: {{ state_attr('sensor.kyle_on_peloton', "Total Work") | float | round(0) }} J
- Output (KJ): {{ state_attr('sensor.kyle_on_peloton', "Output Kj") | float | round(2) }}
- Calories (KCal): {{ state_attr('sensor.kyle_on_peloton', "Calories KCal") }}
{% if state_attr('sensor.kyle_on_peloton', "Leaderboard Rank") != "None" -%}
- Leaderboard Rank: {{ state_attr('sensor.kyle_on_peloton', "Leaderboard Rank") }} / {{ state_attr('sensor.kyle_on_peloton', "Leaderboard Users") }} ({{ 100 - (100 * (state_attr('sensor.kyle_on_peloton', "Leaderboard Rank") | int ) / (state_attr('sensor.kyle_on_peloton', "Leaderboard Users") | int)) | round(0) }}%)
{%- endif %}
theme: solarized_light

@edwork
Copy link
Owner

edwork commented Nov 21, 2022

Hello! Thanks for reporting this issue.

The problem is that a few versions ago there was a single sensor with many state attributes and now there are many sensors with those same attributes broken out into individual sensors. This is the method the core HASS project would like integrations to follow.

Anyway - this not only breaks this card which is referencing state attributes, it's further broken because certain attributes are no longer being reported.

This can all be fixed but it's just slightly more complicated than finding/replacing names. I'll rework this soon and try to add back to the main sensor list the items that are missing.

Thanks!
Ed

@edwork edwork added the bug Something isn't working label Jan 16, 2023
@edwork edwork self-assigned this Jan 16, 2023
@Cassock
Copy link

Cassock commented Feb 6, 2023

@kylewilliams321 did you ever sort out an updated yaml/template for the new sensors?

@edwork
Copy link
Owner

edwork commented Feb 6, 2023

Hello,

@Miablo did an amazing job re-working the markdown card template - take a look at the new template in the development branch. I'll merge it into the main branch soon, I just need to adjust the instructions and generalize the usernames.

@Cassock
Copy link

Cassock commented Feb 7, 2023

Thanks, @edwork and @Miablo. That's the template that I'm using (with updated user/sensor names), but it's only showing the title with no data. The sensors appear to be working fine in ha/developer-tools/state, though 🤷
image

@Miablo
Copy link
Contributor

Miablo commented Feb 7, 2023

@Cassock Can you add your code or a screenshot of it to the post so I can take a look?

@Cassock
Copy link

Cassock commented Feb 7, 2023

@Miablo
Copy link
Contributor

Miablo commented Feb 7, 2023

Can you try this to see if it renders correctly: https://hastebin.com/share/ibenupuvoh.bash - that should have your username added for the sensor

@Cassock
Copy link

Cassock commented Feb 7, 2023

It doesn't :( No errors on the lovelace editor, but putting it into the dev tools template editor results in this:
image

@edwork
Copy link
Owner

edwork commented Feb 7, 2023

Markdown with markup tags won't render in the template dev tools, that's working as intended. The first example provided seems to have stripped out the markup tags possibly breaking the card's formatting.

Can you create a new markdown card, add the text, and force refresh (shift+refresh) the page? In my testing client side caching was causing some errors when I first began testing the card.

@Cassock
Copy link

Cassock commented Feb 7, 2023

Yeah I tried that first before going to dev tools. Here's what it looks like (even after hard refreshes):
image
And just to confirm, it appears I do have working sensors (I assume all of the unknown values correspond to active ride data)
image

@edwork
Copy link
Owner

edwork commented Feb 8, 2023

There's something wrong with the copy-pasta that happens either in or out of GitHub, I'll work it out but for now try out this example.

@Cassock
Copy link

Cassock commented Mar 15, 2023

Spent a few more minutes on this today and it looks like something on the Latest Workout Metrics markdown is what's preventing the whole card from showing. If I delete that section, the rest of the data shows up as expected:
image

@rwijbenga
Copy link

I did notice the problem occurs when for example my Cadence sensor is Home Assistant is displaying unknown. Is goes to unknown when I am not biking. During a ride is works as there is data, and the template works fine.

So I think we need a way to keep the latest sensor value for those sensor that go to unknown when not riding or when switching to a tread.

That goes for the Active Calories, Cadence, Resistance and Speed sensors, 10 total.

Or a change in the template ??

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

5 participants