Zwift Sensor Component - Feedback and Testers Needed

Unfortunately, that information doesn’t come from the “polling” API that this integration (and the Python Zwift client) rely on.

There is a secondary connection that the companion app initiates that is more of a “push” based communication protocol. Ogadai started working on that here:

but it was never fully implemented/researched. If someone were to continue building this out, I think we could get a lot more information out of Zwift. It looks like HomeAssistant would have to open a port to allow incoming communication, and that it comes from a local Zwift client, so HomeAssistant and the Zwift client would need to be on the same subnet.

Hello All,

I’ve been amazed by all your great work, a bit of a noob but very eager to learn. I’ve managed to get de hacs installed and the zwift sensors working. got a nice chart showing all data. But how do i get the really fancy ones you guys seem to have. I tried using markup card and code provided in earlier comments, but failed miserably . can anyone point me in the right direction?

greetings ditalles

figured it out myself

I wonder if this button is available to trigger. The one top right that gives 100 ride ons to people you follow currently zwifting?

ooh, not sure. however, there is a “ride on” endpoint to the API that would allow giving ride ons… you have to give it an ID of a player though. This could be exposed as a service


Hi This is cool. I am abit of a Noob but have the left hand panel working, 
but cant figure out how to customise the main heading i have like Zwift Speed (Andy) 
.  So how to remove Zwift from all heading and my (name)

Also stuck on how to get the image to appear

@quartapound it’s been a couple weeks, how has your revision to the gradient worked out? If you have recommendations we can implement in the integration.

If you are configuring your lovelace UI, you can edit the Entity card and press “show code editor” at the bottom left. This will give you an area that you can override the name of the entity:

Thanks Snickers,

@phillprice bad news on the “ride on”, it looks like the developer API does not support giving Rides Ons right now. If we can figure out that companion app connection, it’s possible that there may be a way to do it through that connection. It’s a bit beyond my current understanding as well as available time.

Just wanted to say thanks for the work on this.

I’m making use of it, with some conditional cards, so we get the following when not online, showing profile information and last session details, with correct wording for cycle vs run, and pace rather than distance climbed if the last activity was a run:

Then when online, the cards swap around, so rather than showing the last session details, it shows stats from the current session:

Now with added “progress within current level” bars…

Capturelevelprogress

these are cool! Mind sharing your config for the progress bars? I was just thinking this would be a cool thing to add to my config while I was riding last night

This is what I’m using inside an entities card, along with the pull request I’ve put in to your repository:

For the cycle one:

      - color: darkorange
        entity: sensor.zwift_cycle_progress_xxxxxx
        entity_row: true
        height: 20px
        name: Cycle Progress
        positions:
          indicator: 'off'
          name: inside
          value: 'off'
        style: |-
          bar-card-currentbar, bar-card-contentbar, bar-card-backgroundbar {
          margin-top: 10px;
          }
        type: 'custom:bar-card'

And the run one:

      - color: deeppink
        entity: sensor.zwift_run_progress_xxxxxx
        entity_row: true
        height: 20px
        name: Run Progress
        positions:
          indicator: 'off'
          name: inside
          value: 'off'
        style: |-
          bar-card-currentbar, bar-card-contentbar, bar-card-backgroundbar {
          margin-top: 10px;
          }
        type: 'custom:bar-card'

Bar card is from https://github.com/custom-cards/bar-card installed via HACS.

ha! wow, I didn’t even notice that PR yet, it looks like we were thinking the same thing yesterday. and I can’t believe i built all this complex math into determining the level for cycling when it’s been on the player profile this whole time!

I’ll review, send some comments your way, and we can get it integrated.

The integration has been updated to 2.2 on HACS!

Changes:

  • new progress to next level sensors
  • level and progress sensors for running
    (Thanks to @badguy for the PR!)
  • properly handles i/o calls in the event loop
2 Likes

Major bugfix update to v3.0!

Please make sure you update from HACS or Github as soon as possible.

I recently discovered some pretty heavy data usage coming from my HA instance. After some investigation (and wrongly blaming the alexa_media integration), I found this integration was hitting an API endpoint that retrieved basic data about all online players in Zwift. Prior to everyone staying inside due to COVID-19, this was not a large amount of data. However, at this time, there are >7500 players online, and this was 1-2mb every 15 seconds when offline, and every second while online.

The latest version remedies this issue (and as a result, might be significantly snappier with data updates), but there may be some differences in the attributes exposed on the zwift_online_xxxxxx sensor, so your template sensors may require updating (thought hopefully not)

Hi Snicker, first of all I wanted to thank you for your great work.
Since I installed new v3.0 I have had several issues, I am not sure if it is a v3.0 problem or if I have to modify something in my configuration.
Sometimes “Last ride” is not updated and also sometimes “Zwift online” stays off when I’m riding.

Sorry to hear that. Please try restarting HA and let me know if it persists. It’s possible that login information for Zwift is decaying, as V3 did remove some “auto-re-log-in” logic that I did not think was necessary. My system has been up for 3 days straight and I have been on Zwift each of those days without any issue in updating, but last week I did have an instance where it did not show I was online (before V3).

I’ll keep troubleshooting and see if it happens to me.

I seem to be hitting this now too - looks like my login timed out in the early hours of this morning. Now seeing the following in the logs:

2020-05-16 04:34:00 ERROR (ZwiftSensor (name:Zwift) update thread) [custom_components.zwift.sensor] something went major wrong while updating zwift sensor for player xxxxxx
Traceback (most recent call last):
  File "/config/custom_components/zwift/sensor.py", line 321, in _update
    player_profile = _profile.profile or {}
  File "/usr/local/lib/python3.7/site-packages/zwift/profile.py", line 12, in profile
    return self.request.json('/api/profiles/{}'.format(self.player_id))
  File "/usr/local/lib/python3.7/site-packages/zwift/request.py", line 37, in json
    resp.status_code, resp.reason))
zwift.error.RequestException: 401 - Unauthorized
2020-05-16 04:34:00 ERROR (ZwiftSensor (name:Zwift) update thread) [custom_components.zwift.sensor] something went major wrong while updating zwift sensor for player yyyyyy
Traceback (most recent call last):
  File "/config/custom_components/zwift/sensor.py", line 321, in _update
    player_profile = _profile.profile or {}
  File "/usr/local/lib/python3.7/site-packages/zwift/profile.py", line 12, in profile
    return self.request.json('/api/profiles/{}'.format(self.player_id))
  File "/usr/local/lib/python3.7/site-packages/zwift/request.py", line 37, in json
    resp.status_code, resp.reason))
zwift.error.RequestException: 401 - Unauthorized

Edit to add: when I restarted HA, it has picked up today’s ride, I’ll keep an eye on the logs and see if it goes unauthorized again in time.