Zwift Sensor Component - Feedback and Testers Needed

I’m trying to get the attribute total distance and total time om Zwift trough the sensor.zwift.online

I’m trying this, bu it just says unknown ?? ( I have my ID instead of the XXXX)

  • platform: template
    sensors:
    zwift_totaldistance:
    friendly_name: Zwift Total Distance
    entity_id:
    - sensor.zwift_online_XXXXX
    value_template: “{{ state_attr(‘sensor.zwift_online_XXXXX’, ‘TotalDistance’ }}”

You might find it easier to do with the newer helpers -
Settings > Devices & Services > Helpers > Create Helper > Template - Template a Sensor

As it is easier to edit them. You want a lowercase T for totalDistance though and a close bracket after the totalDistance

thank you very much. I got it :grinning:

I found this integration today and I was already thinking about automatic fans with heartbeats control.
Esp32 and pwm controller maybe the hw but I need to learn how to create it

See my own made Node red script, which I posted in this topic on August 27th, maybe it will help you.

I m not very good into programming… I more an hw guy.
Ahahha… Never used node-red

I bought a cheap 3 speed floor fan, most of these come with 3-4 wire motors on them already with built in circuits to control motor speed based on 120V input to each wire, so you don’t need to use PWM. PWM will also typically cook AC motors.

I hooked up a SONOFF 4CH but you could use any 3+ relay ESP8266/32 board out there for cheap.

I wrote a small custom output for ESPHome and included that. Links to my code below. Critical is just having the appropriate interlocks configured at a minimum. the other code helps manage a dimmable light and ensures that all of it is exposed as a multi speed fan element inside of HA rather than a set of relays.

There should be nothing else Zwift related installed on the server but this integration. Is this integration doing 12,000+ DNS queries per day?

I installed AdGuard on the server and uncovered us-or-rly101.zwift.com being the top query by far. I don’t think there are any ill effects, so just curious.

image

I just joined Zwift last week and then hunted for any plugins and found this.

Thanks for all the great work. I’ve already got coloured RGB lights behind the TV for HR zones and will also rig up my fan too.

2 Likes

theoretically, yes, this does not seem like a high number of queries, which shouldn’t really be that impactful as Adguard should be caching those responses. The default offline update interval is 15 seconds- so even if you weren’t online in a given day, you should expect to see about 5,700 queries. If you are online, we are checking the API every 2 seconds (though the integration will back off a quarter second at a time if it is throttled, so it could be slightly less frequent) and making multiple calls.

1 Like

Thanks for the clarification on possible number of the queries as it makes sense now why I see drastic range some days. :bike::sweat_smile::cold_sweat::hot_face:

Once again, thanks for the great integration.

Thanks the RGB light idea. I have an underutilised RGB shelf light that’s about to see a lot of red with me. :joy::hot_face:

Here is my automation that every few minutes checks watts and either turns AC cooling on high or fan only on low based on the criteria. Once Zwift goes offline, AC turns off.

There is a dumb fan that’s always on in front of me so this automation supplements the flow and cooling needs accordingly.


alias: Zwift Frosty
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.zwift_online_213
    to: "True"
condition:
  - condition: state
    entity_id: climate.frosty
    state: "off"
action:
  - repeat:
      sequence:
        - choose:
            - conditions:
                - condition: numeric_state
                  entity_id: sensor.zwift_power_213
                  below: 200
              sequence:
                - service: climate.set_fan_mode
                  metadata: {}
                  data:
                    fan_mode: low
                  target:
                    entity_id: climate.frosty
                - service: climate.set_hvac_mode
                  metadata: {}
                  data:
                    hvac_mode: fan_only
                  target:
                    entity_id: climate.frosty
                - delay:
                    hours: 0
                    minutes: 1
                    seconds: 0
                    milliseconds: 0
            - conditions:
                - condition: numeric_state
                  entity_id: sensor.zwift_power_213
                  above: 200
              sequence:
                - service: climate.set_fan_mode
                  target:
                    entity_id: climate.frosty
                  data:
                    fan_mode: high
                - service: climate.set_hvac_mode
                  metadata: {}
                  data:
                    hvac_mode: cool
                  target:
                    entity_id: climate.frosty
                - delay:
                    hours: 0
                    minutes: 5
                    seconds: 0
                    milliseconds: 0
      while:
        - condition: state
          entity_id: sensor.zwift_online_213
          state: "True"
  - service: climate.turn_off
    target:
      entity_id: climate.frosty
    data: {}
mode: single

Just installed this and got it running, did my first ride today. Thank you for this! I’m going to go back through some of the examples and cards.

Fairly new to this, but I have RGB lighting zones working OK…:slight_smile:

However, can I add a second Zwift account as my wife and I share our trainer.
Thanks

you should be able to add your wife’s ID to the players section of your configuration:

sensor:
  - platform: zwift
    username: !secret my_zwift_username
    password: !secret my_zwift_password
    players:
      - <your wife's player id here>
1 Like

Hello

Need a little help with calulating average speed this is working, however it is not rounding the end result as expected

{{((states.sensor.zwift_online_XXXXX.attributes.latest_activity.distanceInMeters | int / 1000) | round (2) ) / (states.sensor.zwift_online_XXXXX.attributes.latest_activity.movingTimeInMs | int / 3600000) | round (2) }}

image

Using each of the attributes in a template yields the 2 decimal result but together not so much.

Been doing battle with this for a couple of days now

Hello,
try like this :
{{((states.sensor.zwift_online_5835990.attributes.latest_activity.distanceInMeters | int / 1000) / (states.sensor.zwift_online_5835990.attributes.latest_activity.movingTimeInMs | int / 3600000)) | round (2) }}

1 Like

Thank you that solves it the original way I wanted too…

image

I did have a workaround for my lack finding a solution by implementing it as a statistic

    - platform: statistics
      name: "Zwift Online 24118 Average Heart Rate"
      entity_id: sensor.zwift_heart_rate_24118
      state_characteristic: mean
      max_age:
       hours: 24
      precision: 0

Which I still use to display Avg HR - only catch is it only to shows the last 24 hours, so if you haven’t ridden in 24 hours the entity goes to “Unknown”

I love this component, and everything works fine. But for some reasons the integration is sometimes not connected to zwift, and i have to restart homeassistant to get it work. is it possible just to restart the integration?

Now the integration is also random disconnected during a workout…

Found this in my log today:

2024-07-25 17:39:47.451 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to import_module with args (‘google._upb._message’,) inside the event loop by custom integration ‘zwift’ at custom_components/zwift/zwift_patch/zwift_messages_pb2.py, line 5: from google.protobuf import descriptor as _descriptor (offender: /usr/local/lib/python3.12/site-packages/google/protobuf/internal/api_implementation.py, line 41: mod = importlib.import_module(mod_name)), please report it to the author of the ‘zwift’ custom integration

For developers, please see Blocking operations with asyncio | Home Assistant Developer Docs