Hi guys, I need a bit of help. I have a vacuum cleaner that I use with the congatudo addon, and its great, the only problem I would like to have is a better statistics.
Basically while it cleans, there are 2 sensors “sensor.current_statistics_area” for the area cleaned in cm2 and “sensor_current_statistics_time” in seconds, after the robot has returned to its dock or changed the stratus from cleaning to docket or error for few seconds, this values return to 0.
I created a number helper and created an automation that when the robot changes the status from cleaning to return to dock or error to export the current data from sensor.current_statistics_area to the helper using action input number set with the code bello, this is great, but I would like to set the date not in cm and seconds but in meters and minutes.
Question1: how to I set the data to be the sensor data divided by 60 to get minutes from seconds, and by 1000 to get meters from cm.
Question2: for the fime sensor, instead of a number helper can I use a date helper and set the date in format hh:mm:ss?
service: input_number.set_value
data_template:
entity_id: input_number.conga
value: "{{states('sensor.valetudo_meagercreamyrail_current_statistics_time')}}"
Thank you.
With the the expansion of template sensors, these both could be handled by trigger-based template sensors. If you want to go that route, post your automations so we can see what triggers you are using.
For whole minutes you can use //
as shown below, if you prefer to see minutes with decimals use /
instead.
service: input_number.set_value
data:
value: "{{states('sensor.valetudo_meagercreamyrail_current_statistics_time) | int // 60}}"
target:
entity_id: input_number.conga
You can, but only up to 24hrs… then it gets messy. You’d be better off using an input text or template sensor.
Thank you, this is what I was looking for.
Just for the sake of trying, how do I render a number to timestamp. I created a date helper with just time that is 0:00, I´m trying to use the codes bellow but I keep getting “must contain at least one of date, time, datetime, timestamp”
{{ (states("states.input_number.conga") | int) + (now().timestamp() | int)) | timestamp_custom("%H:%M") }}
{{ as_timestamp(states('input_number.conga')) | timestamp_custom('%h:%m') }}
Based on your examples and previous question I’m assuming you want to save the value of your input number as a time-only input datetime.
service: input_datetime.set_datetime
data:
time: >
{{ states("input_number.conga") | int
| timestamp_custom("%H:%M:%S", local = false) }}
target:
entity_id: input_datetime.ztest_time_only
As stated previously this will become inaccurate after 24 hours of runtime. A better solution is a trigger-based template sensor…
template:
- trigger:
- platform: state
to: "0"
not_from:
- unknown
- unavailable
entity_id: sensor.valetudo_meagercreamyrail_current_statistics_time
sensor:
- name: Valetudo Runtime
state: >
{% set seconds = trigger.from_state.state | int(0) %}
{% set periods = { 3600: 'hour', 60: 'minute', 1:'second' } %}
{% set ns = namespace(seconds=seconds)%}
{%- for p_sec in periods.keys() %}
{%- if seconds >= p_sec -%}
{% set p_name = periods.get(p_sec) -%}
{% set period_value = ns.seconds // p_sec -%}
{% set has_0 = "0" if period_value <= 9 %}
{{- has_0 }}{{ period_value }}{{":" if not loop.last -}}
{% set dif = period_value * p_sec %}
{%- set ns.seconds = (ns.seconds - dif) % p_sec %}
{%- endif%}{%- endfor %}
That its brilliant, thank you fot taking the time. I don’t need more than 24 hours, i will reset the the time to 0 every midnight. Its just so when I look at the dashboard, can get an idea io what the robot has done that day, instead of 00 values. Thank you again.
Brilliant, thank you, exactly what I wanted, although you gave me too many options for the time and I don’t know which one to keep. They all work great, the big 2 tiles are the input numbers for time and area, the first 2 small times are the the original values that are reverted to 0 when the vacuum is docked, the third is the input datetime and the last is the template. Its exactly what I wanted. If I use the template, to set it to 0 at a certain time or when it start cleaning next day, I can do an automation as for the inputs and set the value to 0?
Yes, but it doesn’t require an additional automation, just changing the template a little and defining a second trigger. For the trigger you could use whatever works for you, below I have
shown using a numeric state trigger to reset when the vacuum starts cleaning again.
- trigger:
- platform: state
to: "0"
not_from:
- unknown
- unavailable
entity_id: sensor.valetudo_meagercreamyrail_current_statistics_time
- platform: numeric_state
above: 0
entity_id: sensor.valetudo_meagercreamyrail_current_statistics_time
sensor:
- name: Valetudo Runtime
state: >
{% if trigger.platform == 'numeric_state' %}
00:00:00
{% else %}
{% set seconds = trigger.from_state.state | int(0) %}
{% set periods = { 3600: 'hour', 60: 'minute', 1:'second' } %}
{% set ns = namespace(seconds=seconds)%}
{%- for p_sec in periods.keys() %}
{%- if seconds >= p_sec -%}
{% set p_name = periods.get(p_sec) -%}
{% set period_value = ns.seconds // p_sec -%}
{% set has_0 = "0" if period_value <= 9 %}
{{- has_0 }}{{ period_value }}{{":" if not loop.last -}}
{% set dif = period_value * p_sec %}
{%- set ns.seconds = (ns.seconds - dif) % p_sec %}
{%- endif%}{%- endfor %}{% endif %}
Another option would be a time trigger for a nightly reset:
...
- platform: time
at: "00:01:00"
sensor:
- name: Valetudo Runtime
state: >
{% if trigger.platform == 'time' %}
00:00:00
...
brilliant. 100000000 thanks.