Cat Wheel Speedo 2

a black cat with a yellow collar sits in an upright wheel about 1m high.

Previously I tried to write about how to set up a speedometer for a cat wheel using an ESP32, hall sensor and some magnets. I have now found a much easier way to get the speed into Home Assistant via ESPHome. If you use Home Assistant but don’t already use ESPhome, it’s a great and simple way to get DIY devices made with ESP32 boards into Home Assistant.

As the cat wheel speedo runs on an ESP32, I realised that there’s probably a way to use ESPhome to do this. At first I attempted to get speed by using automations and helpers to try and calculate the speed by keeping a tally of change-of-state of the hall sensor, but it got ridiculously complicated and didn’t work, and then I saw that there’s a pulse counter component in ESPHome that will keep track of a count of “pulses per minute”, simply registering each time the hall sensor activated as a pulse. This was much, much easier as now I had a speed value I just needed to convert to m/s.

This is the YAML for the ESPHome running on the ESP32 that is attached to the wheel. 4 magnets around the edge of the wheel trigger the hall sensor when they pass, generating a “pulse” that is measured by the pulse counter. My hall sensor is connected to GPIO Pin 14 on the ESP32.

sensor:
  - platform: pulse_counter
    pin: GPIO14
    id: wheel_counter
    unit_of_measurement: "m/s"
    name: "Cat Wheel Speed"
    icon: "mdi:mdi-rotate-right"
    update_interval: 1s
    filters:
      - multiply: 0.01167
    total:
      name: "cat wheel revolutions"
      unit_of_measurement: "revs"

The distance between the magnets is 0.7m, so to convert from “pulses per minute” to “meters per second” I multiply it by 0.01167 (the result of (0.7 / 1 pulse) x (1 minute / 60 seconds)). You can also set the update_interval to whatever you want; ms values would give you a real-time speed which could look good if you then added in a physical display to the speedo too.

Also here is the “total” value, which keeps a tally of the total number of pulses. I thought I could multiply it by 0.7 here and get a total distance travelled, but it’s an int and wouldn’t store the decimal, so it’s just a tally of the total number of times the magnets have triggered the hall sensor.

Now to add in useful/fun entities, I created the following in Home Assistant’s config.yaml to get the distance travelled in metres:

  - sensor:
    - name: "Cat Wheel Total Distance"        
      unique_id: cat_wheel_distance
      state: >
        '{{ (states('sensor.esp32_cam_cat_wheel_distance') | float * 0.7) | round(2) }}' 
      unit_of_measurement: "m"
      device_class: distance
    - name: "Cat Wheel Daily Distance"        
      unique_id: cat_wheel_day_distance
      state: >
        '{{ (states('sensor.daily_cat_wheel_distance') | float * 0.7) | round(2) }}'
      unit_of_measurement: "m"
      device_class: distance

Here, I’m calculating a total distance and a daily distance by taking the “cat wheel distance” total and multiplying it by 0.7. It’s the same for both sensors, but for one of them is linked to a helper (Settings -> devices & services -> helpers) that resets the value at midnight.

Also in the helpers section , you can create a Statistics Sensor that gives you the Max value for Cat Wheel Speed, and the time period (eg 1 day, or all time). Or average daily distance? Can you calculate how many calories the cat burns runnign on the wheel? How about rigging up a Home Assistant controlled treat dispenser that issues a dreamie every 50m?

Updated: