Peloton support

Would love to see Peloton support.

Perhaps you should give us a couple of sentences on that peloton is? Because neither of your links give me any damn idea!

It’s a really expensive exercise bicycle.

LOL no wonder I didn’t know!!

/me looks around for wine glass and runny cheese.

1 Like

Good News!

Using the linked API above I was able to scrap something together. The API being used is official but undocumented aside from @geudrik’s documentation (someone please correct me).

My plan is to refactor the code from the peloton-api project directly into the HASS Component, as peloton-api is not published to PyPi, and is already MIT licenced.

For anyone curious about use cases, I am interested in using this to trigger:

  • Lights off
  • Accent lights to blue
  • HVAC to stop cooling and ventilate
  • directed cooling fan on

And reverse when the ride is over.

Quick Edit: I realize the peloton-api project is not just a simple script, and I may look at working with the dev to get it published into PyPi.

image

1 Like

@edwork well done, would be very interested in collaborating or helping test, is there somewhere to follow along on your progress?

Congrats @edwork, this is super exciting! I’ve been looking for the same thing, did you manage to get this working? Let me know if I can help!

Thanks @edwork - this is fantastic! I’m confused on how to install the sensor, though?

I’m running in a docker container, and have

  • Placed the contents from your git into HomeAssistant/config/custom_components/peloton
  • Created the HomeAssistant/config/peloton configuration file with credentials.
  • Added - platform: peloton to my configuration file

However, nothing is loaded into the entities? What steps should we be following to get this going?

Thanks!
Matt

@edwork do you have something working even if rough? I’d love to help with this so I can stop getting yelled at when the basement lights turn off when my wife is on the Bike. :slight_smile:

Hello All,

It’s been a while since I started this, and I could use some help making it more streamlined. First, there are some requirements that we need to work out.

  • I am using geudrik/peloton-api. An unofficial (but working) API. It’s not in PyPi so I have resorted to cloning the project and refactoring certain things such as the credentials in order to get it working.

  • Credentials currently have to be hard coded. This is a VERY solvable issue, I am just not the best at refactoring what’s already built in the API functions. I believe I hard coded my credz in custom_components/homeassistant-peloton-sensor/sensor.py (line 33,34) but if that doesn’t work check in custom_components/homeassistant-peloton-sensor/peloton/peloton.py and look into hard coding them there.

To be clear, most of the terrible workarounds are just to get it to work for proof of concept. Since there’s been much more interest lately (and I need to get back on the bike…) I’m going to try to polish this up a good bit within the next few days.

Checkout https://github.com/edwork/homeassistant-peloton-sensor/ for more details in the Readme (including new setup instructions).

Cheers,
Ed

1 Like

Thanks @edwork! Appreciate the progress on this, even if it’s just MVP… very cool! I’ve been refreshing this page for the last 8 days waiting for this :slight_smile:.

I updated the credentials in 33,34 but was still unsuccessful. I ended up hard coding them into line 268, 269 which worked! I’m not a developer and know just enough about Python to be dangerous… will play around with the code later this week to see if I can help figure out why the variables aren’t passed into the payload on 268,269.

Happy to hear it’s working somewhat. I haven’t poked at this for a while, so couldn’t remember exactly what I had done! Pull requests are welcome, suggestions and critiques are also very welcome!

@edwork Nice Job in this, I was able to get it working as well and would be happy to help test.

One thing I noticed, it never reports anything other than complete as the status, however the attributes do seem to update after a workout is completed. Is that consistent with everyone else’s experience?

Hey - Just wanted to thank you for working on this- can’t wait to try it out. Hopefully it could be included in as a standard HA integration (or installable via HACS) some day.

For anyone interested, I wanted something offline to solve the issue of knowing if someone was using the bike.

I sideloaded the following app onto the Peloton: https://llamalab.com/automate/

The app allows you to make HTTP/S calls during screen on/off events. I use these events to fire a “peloton” event into the HASS event bus with event metadata indicating if the screen is on/off.

I listen to these events in automation to turn fans/lights on and off.

Unfortunately this isnt as elegant as a HASS plugin, but I like the fact that I am getting feedback directly from the bike!

That is interesting…how did you install onto the Peloton?

Sideload using ADB and plugging my computer directly into the Peloton

Can you tell me how you hardcoded it so I can copy paste with my user information please?

I know it’s not ‘elegant’ either, but FWIW I use Google Wifi Mesh setup at my house. I created an ‘IFTTT Event’ when Google Wifi detects my Peloton on the network, it calls a script (which sets a variable / timestamp in HA denoting the Peloton is ON). Another IFTTT Trigger fires when Google Wifi detects the Peloton leaving the network to fire a peloton off script.

scripts:

peloton_on:
  sequence:
    - service: variable.set_variable
      data:
        variable: peloton
        value: 'on'
    - service: variable.set_variable
      data:
        variable: peloton_on
        value_template: "{{ now().timestamp() }}"

peloton_off:
  sequence:
    - service: variable.set_variable
      data:
        variable: peloton
        value: 'off'

binary_sensor:

    peloton:
      friendly_name: Peloton
      value_template: "{{ is_state('variable.peloton','on') }}"

sensors:

    peloton_last_on:
      value_template: >
        {% set elapsed = (as_timestamp(states('sensor.date_time').replace(',','')) - states('variable.peloton_on') | int ) %}
        {% set days = (elapsed / 86400) | int %}
        {% set hours= ((elapsed  % 86400) / 3600) | int %}
        {% set mins = ((elapsed  % 3600) / 60) | int %}
        {% set secs = elapsed | int % 60 %}
        {% if days > 0 %} {{days}}d {%if hours < 10 %}0{%endif%}{{hours}}:{%if mins< 10 %}0{%endif%}{{mins}}
        {% elif hours > 0 %} {% if hours < 10 %}0{%endif%}{{hours}}:{%if mins< 10 %}0{%endif%}{{mins}}
        {% elif mins > 0 %} {{mins}}m
        {% else %} {{secs}}s {% endif %}

I’m sure there are more elegant ways to do this, but, hey, does at least what I need it to do…

Also, FWIW, I use the exact same methodology for our Xbox, Nanny sensor, etc. Anything that comes onto / off of the network I can track like this to see if it’s on or not and how long it’s been on.

Ends up looking like this on frontend:
image

Variable I use is custom component and found here: https://github.com/rogro82/hass-variables (I’m also aware input_* can be used, but I started w/ variables and they work, so sticking with my theme of ‘if it ain’t broke, don’t fix it’ - I kept using them…

Unfortunately I have UniFi and same thing won’t work. Right now the status on this does not change from complete to in progress.