Hello friends,
I want to calculate the mean running time of my heating system.
Therfore I have etnitys for
running hours | float
impuses/start ups | int
to get the the mean I devide the running hours by the impulses.
I get a value somwhere like 3,0958
This value I want to translate into a time display as 03:05:26
I tried the following in the configuration.yaml:
template:
- sensor:
- name: "Laufzeit_WP"
state: >
{% set runtime = states('sensor.luxtronik_311202_026_compressor1_operation_hours') | float %}
{% set impulse = states('sensor.luxtronik_311202_026_compressor1_impulses') | float %}
{{ (states("runtime * 3600 / impulse") | float ) | timestamp_custom("%-H:%-M:%-S", false) }}
Do you guys have any suggestion?
Thanks
paddy0174
(Patrick)
April 25, 2024, 11:56am
2
And it doesnât work? If so, whatâs the error?
This canât work, as you wonât have âstatesâ on that one. Try like this:
{{ runtime * 3600 / impulse | float | timestamp_custom("%-H:%-M:%-S", false) }}
EDIT: donât think so, but Iâm not sure if âruntimeâ might be a reserved word, so not usable for a variable name.
I donât get an actual error. I just dont get a view on the dashboard
Where can I check my code for plausibility?
The timestep command expects a float in seconds, right?
Using your code did not change anything yetâŚcan I force a update after editing the configuration.yaml?
For my learning: when do I use âstatesâ?
francisp
(Francis)
April 25, 2024, 12:39pm
4
Developer tools â Template
> template:
> - sensor:
> - name: "Laufzeit_WP"
> state: >
> {% set laufzeit = states('sensor.luxtronik_311202_026_compressor1_operation_hours') | float %}
> {% set impulse = states('sensor.luxtronik_311202_026_compressor1_impulses') | float %}
> {{ laufzeit * 3600 / impulse | float | timestamp_custom('%-H:%-M:%-S', false) }}
TypeError: unsupported operand type(s) for /: âfloatâ and âstrâ
What does that mean?
123
(Taras)
April 25, 2024, 4:28pm
6
It means the template is attempting to perform an arithmetic operation where one of the values is a floating point number (float) but the other is a string (str) which is not a number and therefore invalid.
As an experiment, copy-paste the following template and let us know what it reports.
{% set laufzeit = states('sensor.luxtronik_311202_026_compressor1_operation_hours') %}
{{ laufzeit }}
{% set impulse = states('sensor.luxtronik_311202_026_compressor1_impulses') %}
{{ impulse }}
It should report two numbers.
It does report two numbert!
But I get back string?!
I understand, I have to translate into binary
binary_sensor:
- platform: template
sensors:
friendly_name: "Laufzeit VD1"
value_template: "{{ states('sensor.luxtronik_311202_026_compressor1_operation_hours') | float(0) }}"
binary_sensor:
- platform: template
sensors:
friendly_name: "Impulse VD1"
value_template: "{{ states('sensor.luxtronik_311202_026_compressor1_impulses') | float(0) }}"
template:
- sensor:
- name: "Laufzeit_WP"
state: >
{% set runtime = states('Laufzeit VD1') | float %}
{% set impulse = states('Impulse VD1') | float %}
{{ (states("runtime * 3600 / impulse") | float ) | timestamp_custom("%-H:%-M:%-S", false) }
}
123
(Taras)
April 25, 2024, 5:38pm
9
Now try this template in the Template Editor.
{% set laufzeit = states('sensor.luxtronik_311202_026_compressor1_operation_hours') | float(0) * 3600 %}
{{ laufzeit }}
{% set impulse = states('sensor.luxtronik_311202_026_compressor1_impulses') | float(0) %}
{{ impulse }}
---
{{ (laufzeit / impulse) | timestamp_custom('%-H:%-M:%-S', false) }}
It should report a value that looks something like this:
3:5:29
1 Like
Yeah that did the trick! Thank you!!!
1 Like