A "I quit smoking" sensor

I quit smoking recently and made a sensor that counts the days that have since passed. In case you want to use it just change the date in the strptime():

- platform: template
  sensors:
    nonsmoker:
      value_template: '{{ (( as_timestamp(now()) - as_timestamp(strptime("06.07.2018", "%d.%m.%Y")) ) / 86400 ) | round(2) }}'
      friendly_name: 'Nichtraucher'
      unit_of_measurement: "Tage"

Now add the new sensor to your customize.yaml and give it a matching icon:

sensor.nonsmoker:
  icon: mdi:smoking-off

Voilà! It looks like this:
nonsmokersensor

10 Likes

This is great sensor code for any type of date related sensor… Nice work! and keep up the battle to quit smoking!

2 Likes

How do you get that fuel price?

Take a look at this thread. Fuel price is provided bei tankerkoenig.de. You need an API-Key:

1 Like

Too bad…

Hier gibt es den einfachen Zugang zu den aktuellen Spritpreisen aller an die Markttransparenzstelle für Kraftstoffe (MTS-K) meldenden Tankstellen Deutschlands.

I live in the Netherlands, so that won’t be of use.

A little bit offtopic, but…
You can scrape the data, I do this to extract the local gasprice for the nearest Shell Express station.

  - platform: scrape
    resource: https://www.shellexpress.nl/nl_nl/station/se-nieuwerkerk-aan-den-ijssel
    name: Shell Express
    select: ".price-actual"
    value_template: '{{ value.split(" ")[0] }}'
    unit_of_measurement: "EUR/L"

image

3 Likes

Also off topic but I was looking for a dutch way to do it. I am using this app on my phone to get the cheapest gas prices around my position: https://directlease.nl/tankservice/

Maybe there is a way to gather the data from here for a bit more option than just shell.

Good job on quiting smoking OP.

Nice how you added it to Home Assistant

1 Like

OFFTOPIC

I checked that. The website has an api call for getting all stations with lat/lon. But from that you can only get to the station prices from a png image. That is of no use.

I tried mitmproxy to sniff the app, but that uses https/ssl traffic, so SSL certificates were invalid and therefor I was unable to read which api calls are made.

Perhaps someone with more technical skills can reverse-engineer the iOS app.

I was also thinking of scraping from

https://www.unitedconsumers.com/tanken/informatie/brandstof-prijzen.asp

or

https://www.unitedconsumers.com/tanken/informatie/brandstof-prijzen/euro95

but I was having a hard time getting the filter right.

@jay448 @Bob_NL I suggest we start a new topic to continue this discussion.

Update: this discussion continues over here:

@jones sorry ask you but i dont understand. 1.65 tage is what??

Google: translate tage to English

German: tage
English: days

Google: translate Nichtraucher to English

German: Nichtraucher
English: non smoking

i believe its actualy nonsmoker

Thanks. It would be nice if we could improve the translator

1 Like

Right! My Homeassistant is a weird mix between German and Englisch. Sorry about that.

mine is even more wierd.

i got mostly dutch, but its also partly german and partly english :wink:

1 Like

Thank you jones! I have never smoked but did implement the Tankerkönig. Works flawlessly! Great stuff!

1 Like

@GraysonPeddie yes tage is days, but 1.65 is what? 1= one day and .65???

hmm, that isnt that hard to understand.
1.65 days is 1.65* 24 hours

so .65 is 15 hours and 10 minutes

1 day and 15.6 hours. 0.6 hour is 36 minutes.

oops, i calculated wrong. thx for correcting :wink:

1 Like