I have a service call to calibrate my CO2 sensor after opening the window for ventilation using mhz19_calibrate_zero, Now I want my dashboard to show the time since the last recalibration. I know I need something like what I found in another thread:
Yes, devices may have states you can latch onto. In my Esphome I have:
# Enable Home Assistant API
api:
password: ""
services:
- service: mhz19_calibrate_zero
then:
- mhz19.calibrate_zero: sensorid
and my automation is:
alias: Raum-6-Calibrate-CO2
description: ""
trigger:
- platform: state
entity_id:
- timer.lueften
to: active
for:
hours: 0
minutes: 12
seconds: 0
condition: []
action:
- service: esphome.a03_mhz19_calibrate_zero
data: {}
mode: single
There, in the automation I’d need to set some timestamp to now() and place that into the relative_time() in the dashboard. Only I do not know the correct syntax.
According to what I’m understanding is you want to set a timer. This is how I set my timers, I just use seconds but it wouldn’t be hard to modify for minutes/hours. I have an input_number helper that changes based on sun.sun so during the day my light timer is 15 minutes at night it trims to 7 minutes. I make that into seconds and use it here. but the format for duration is 00:00:00 if you don’t include any : it defaults to seconds, if you want to set minutes then 05:00 would be 5 minutes, hours then 01:05:00 would be 1 hour 5 minutes. (Again I prefer seconds, easier to work with helpers)
Then to display on a dashboard, I would use an entities card, there might be better options, perhaps a mushroom entities card? Look at options there. But this works and regardless of how you set your time this will show in relative time hh:mm:ss or it will say Idle.
No absolutely not. I use timers, they run backwards for a set amount of time. What i want to do here is store (and reset) a fixed point in time and show how long ago it was. But your
- service: input_datetime.set_datetime
seems to be the way to go. I’ll try that and report back.
let me verify what i think you’re asking. you have an automation that calls esphome.a03_mhz19_calibrate_zero. you want a sensor to tell how long it’s been since that automation was run. is that right?
if so, that shouldn’t be too hard. if your automation is called automation.raum_6_calibrate_co2 then your sensor should be something like:
note that tihs will give the amount of time that has passed since that automation was called. if someone calls esphome.a03_mhz19_calibrate_zero directly, it won’t catch that.
you don’t need to store away a separate date time helper because the automation already stores the last time it was run.
With your help I nailed it – not perfect but good enough. Contrary to my expectations both a duration and relative_time() yield not a number but a string, “8:26:10.12545” and “8 hours” respectively and neither of them nice. So I reverted to showing the absolute time. I have a templates.yaml but for small things I prefer the UI, so I can’t show the solution in full. The template I use and display is:
BTW I learnt something else important. When I write a new automation and then rename it, the new name is only an alias. It is the first name with all its typos that will be retained forever in the id. Thus the R6 vs. Raum-6 mixup. I’ll try to look out for that mistake in future.