That’s not a problem at all @snicker, I like learning new stuff, so it wasn’t too difficult to figure out. But I can see a lot of guys find your great integration without necessary experience and it may be bit of a steep curve I know I’ve spent quite some time digging around.
I’ll write something down from my notes when I have a minute and if you want, feel free to add it under installation instructions.
Need a bit of advice here, I am trying to code up LEDs which change colour the higher my heart rate goes on Zwift.
Firstly thanks for all the posts, helped me along thus far, and apologies if in wrong thread. Admin please feel free to move this post if required.
The Sensors I am using I got from the git on this page.
Hardware I am using is:
D1 Mini
WS2812B LEDs
Connected with jumpers (5v, G, D4 data)
Used ESPhome to connect.
In automations, below I will place the code, So far I have only input the thresholds of the different heart rate, will get to the colour change once I get it to trigger.
When I execute the automation through the UI in Home Assistant it works, but when I am on Zwift it does not work. The data is going into home assistant as I have built a Grafana Dashboard which shows the heart rate data live, and it works.
I have set up the LED as a entity also
What am I missing here? Any help greatly appreciated.
Love your Lovelace card.
I did notice that the Zwift sensor doesn’t give a nice duration. If you rode 1 hour and 24 minutes, you don’t want it to say 1:24 Minutes. It also doesn’t look like the data coming in is formatted so well, either. So, if you were to ride 1 hr and 4 min, the duration comes back from Zwift as 1:4. This code fixes it to be in the format 1h:04m.
{% set value =
states.sensor.zwift_online_XXXXXX.attributes.latest_activity.duration%}
{% set parts = value.split(":") %}
{{ parts[0]}}h:{{'{:02}'.format(parts[1]| int)}}m
{% set value = states.sensor.zwift_online_xxxxxx.attributes.latest_activity.duration|string %}
{% if ':' is in value -%}
{% set parts = value.split(":") %}
{{ parts[0]}}h:{{'{:02}'.format(parts[1]| int)}}m
{%- else -%}
{{ value}}m
{%- endif %}
This should load the duration into ‘value’ then check if it includes a ‘:’ split it into parts, and display as 12h:34m if it does, or just display 56m if it doesn’t include a ‘:’ and not try and do the split.
Badguy,
You beat me to the punch. My less elegant fix was this:
The {% if last_act['sport'] == "CYCLING" -%} ride {%- else -%} run
{%- endif %} duration was
{% set value = states.sensor.zwift_online_XXXXXX.attributes.latest_activity.duration %}
{% set parts = value.split(":") %}
{% set duration_length = parts | length %}
{% if duration_length == 2 -%}
{{parts[0]}}h:{{'{:02}'.format(parts[1]| int)}}m
{%- else -%}
{{parts[0]}}m
{%- endif %}
@badguy@vk2him
And, like a fool, I didn’t edit my Zwift ID out of my post. So, if you wouldn’t mind, could you, please, edit it out of your reply posts?
Awesome work! I new to Home assistant (been using it for a month now) and I finnaly got this Zwift implementation to work. I’ve used @badguy his example to create my own dashboard. Learned a lot!
I use the heart rate sensor to control my two fans. Really awesome. Nextup is pain cave lightning that changes when going deep or taking it easy…
One small issue… My bar-card does not allign properly with the entity icon. Did you change something?
Nevermind! I was missing a plugin…
In order to get your dashboard to work. I had to add layout-card, bar-card and card-mod. The last one did the trick with the allignment.
To get it a little bit more alligned with the other entities, I’ve added a few allignment options
For the Ride On Sensor… I’ve found a Powershell script online that reads the log file and counts the ride ons, ride ons given and reads the name of the player that gave the ride on.
It works only on Windows (since it is powershell) and Zwift must run from that Windows computer.
The script outputs these number to a file.
Now I made some changes so that it only outputs a number (ride ons received) and writes this to a file in the config folder.
Then I use a File sensor to read the number in the file, and tadaah… I have A Ride On Entity.
Setting the update interval to 1 second makes it pretty fast. I see the thumb in game, and the number on my dashboard changes at the same time. This will depend on your network…
I know it is pretty dirty, but this works for now…
Now I need to create a script that checks if the number goes +1 and create an activity. Also change the update interval with a script when online, so it doesn’t check every second when not online.
This should also work when riding through an arch, go up one level, since this is all in the log file.
I know there will be other ways to do this, so if someone has a suggestion, let me know…