Sensor that activates on a certain increment

I have TeslaMate sending my HA instance real-time info about my car, one of which is the odometer for my car. I’d like to create a notification so that every 7000 miles, I get notified that it’s time to do a tire rotation. So basically notify me at 7000, 14,000, 21,000, etc. Ideally I would want it to nag me daily until I’ve actually done the rotation and then “reset”. I was thinking it could just be a binary sensor that turns “on” when I’ve reached the required mileage and would nag daily until I manually turn it “off”. That sensor would turn back on again after another 7000 miles and so forth.

Any thoughts/ideas on how to implement this? Thanks!

So what should happen if you wait until 8000 miles?
Should it turn on at 14 000 or 15 000?

Good question. I’d like to think I’ll get it done right away. To simplify, I’m fine with doing the set increments based on the initial value (so 7k, 14k, etc.). But if it’s possible to increment on the value it was when it turned “off” (i.e. 8k) then that would be extra cool.

Sure you will. Sure…

If I’m not mistaking then input number and input text saves it’s value even after reboot and upgrades.
I have an old state since before my SD card crashed on me. So it should work.

The way I think of it is to flip a boolean on at 7000 using an automation.
Then when the boolean is turned off you save the milage + 7000 in a text or number and use that as the next automation as the trigger.

So the first automation is just to get it going, then the second automation will be the one that keeps it going.

Option 1
The basic incremental part is easy, just create a template binary sensor with a modulo function:

{{states('sensor.tesla_mileage')| round | int % 7000 == 0}}

Use that to turn on a boolean.

Option 2
To follow @Hellis81’s suggestion you could have your “reset” button call a script to add 7000 to your current mileage and save that to an input number and flip your boolean back to “off”…

alias: Next tire rotation mileage
sequence:
  - service: input_number.set_value
    target:
      entity_id: input_number.next_mileage
    data:
      value: {{ states('sensor.tesla_mileage')|round|int + 7000 }}
  - service: input_boolean.turn_off
    target:
      entity_id: input_boolean.tire_rotation
mode: single

Then use a template trigger to turn on the boolean when your current mileage matches your input number (I would use “>=” to be sure to catch the event).

{{states('sensor.tesla_mileage')| round | int >= states('input_number.next_mileage')}}

From there you just have to decide what type of alerts you want… notifications, tts, blinky buttons on lovelace, threatening emails… :grin:

This is great! Thank you! Will try and implement this weekend.

Actually, one potential issue I see with this is that using the modulo function, the Tesla would need to report the mileage within a one mile window (6999.50 to 7000.49). So if I drive that one mile and HA doesn’t pull in the value within that window, it will essentially skip “True” and I would miss the notification.

You can floor the value to thousands using (x/1000) | int *1000

Meaning:

{{(states('sensor.tesla_mileage')/1000| int *1000) % 7000 == 0}}

This results in:
6000-6999 = 6000
7000-7999 = 7000

So as long as you get an update within 1000 miles then it should trigger

Just another idea, loosely defined: How about an input datetime to store the last time you actually rotated and another input to store the default interval? You can have a third input that then counts down to zero km/mi (left before you must rotate again). If the value is less than or equal to zero, notify daily at some scheduled time. When you update the last rotated input, you reset the countdown. With this you can then do more things, like, if it’s still 1000 to go, send a courtesy notification. When zero or less, send a critical notification. A bit more complex but a bit more flexible (maybe).