I’ve been fighting with this all day and can’t seem to get this completely worked out. Each one of these is close, but doesn’t fully resolve. Plus, on the last two, I don’t even fully understand the syntax.
The history_stats integration reported that the Tree Sprinklers ran today for .14 hours. Converted to minutes, that’s 8.4 minutes. Converted to minutes/seconds, that’s 8 mins, 24 seconds.
My attempts and issues are below:
The first one doesn’t work because it doesn’t parse out seconds from minutes. The split(.) is required. Not really sure how to implement this here. Hell, this doesn’t even give the correct answer.
sensor:
- platform: template
rainmachine_convert_hh_to_mm_ss:
unit_of_measurement: 'Mins'
value_template: {{ (states('sensor.side_yard_runtime_today') | float * 60) }}
The second one doesn’t work because it does the same math to the number in the tens place. This resolves to 8 min, 8 seconds, which is also wrong.
sensor:
platform_template:
rainmachine_convert_side_yard:
friendly_name: "Tree Sprinklers Duration"
entity_id: sensor.tree_sprinklers_runtime_today
value_template: >
{% set time = (states('sensor.tree_sprinklers_runtime_today')) %}
{% set minutes = ((time | float * 60) | string).split('.')[0] %}
{% set seconds = minutes | int % 60| round(0) %}
{{minutes}} Minutes {{seconds}} Seconds
The last one doesn’t work because the number in the tens, hundreds, and thousands place is saying 240 seconds, not 24 seconds. This would work, but round(2) does not seem to be working (at least in the template configurator).
sensor:
- platform: template
sensors:
rainmachine_convert_side_yard:
friendly_name: "Tree Sprinklers Duration"
entity_id: sensor.tree_sprinklers_runtime_today
value_template: >
{% set time = states('sensor.tree_sprinklers_runtime_today') | float %}
{% set minutes = ((time %1) * 60) | int %}
{% set seconds = ((minutes %9) * 60 /2 ) | float | round(2) %}
{{minutes}} Minutes {{seconds}} Seconds
Finally, I don’t even understand some of this. In the second example, I get that I’m setting the time variable to be the state output for the sensor. I believe the leading % and ending % in the curly braces are used to evaluate the statement. I understand that when I set the minutes variable, that I’m taking the time, using float and multiplying by 60 to get the minutes. The output is converted a string and then split using the decimal. However, I have no idea what the [0] does, except when I change it, it halves the result. I also don’t understand the section when I’m setting the seconds variable, what does int % 60 mean (specifically, the %)?
In the third example, where I’m setting the seconds variable, what is ((minutes%9)? Why does that give me a better answer than ((minutes%1)? What is happening here?
At any rate, please help. I’m finally waving the flag - I’m stuck.