Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] UPS runtime_left time format #245

Open
clau-bucur opened this issue Sep 6, 2022 · 4 comments
Open

[Feature] UPS runtime_left time format #245

clau-bucur opened this issue Sep 6, 2022 · 4 comments
Labels
enhancement New feature or request more info needed Need more information planned To be implemented in future release

Comments

@clau-bucur
Copy link

Is your feature request related to a problem? Please describe.

Currently the attribute "runtime_left" is not eaily used in templates because it's format is not a standard time/timedelta.

Describe the solution you'd like

Would it be possible to format the runtime_left attribute in such a way what it's compatible with the as_timedelta filter ? (taken from docs: Expects data in the format DD HH:MM:SS.uuuuuu, DD HH:MM:SS,uuuuuu, or as specified by ISO 8601 (e.g. P4DT1H15M20S which is equivalent to 4 1:15:20) or PostgreSQL’s day-time interval format (e.g. 3 days 04:05:06))

This way this attribute is easier to be used in automations and scripts that rely on the time left on battery.

Describe alternatives you've considered

Converting the current attribute value inside the template before filtering it with as_timedelta.

@clau-bucur clau-bucur added the enhancement New feature or request label Sep 6, 2022
@tomaae
Copy link
Owner

tomaae commented Sep 6, 2022

it is in iso8601, just missing pt mark.
but I dont know if HA has an element that supports time format without being full datetime.

@clau-bucur
Copy link
Author

It has, called timedelta, and this attribute fits perfectly.

@tomaae
Copy link
Owner

tomaae commented Sep 6, 2022

you are talking about python there, not HA.
I just had a look and HA knows date, timestamp and duration.
Duration would be only one that is in such format, but it is defined as "fixed duration", so not sure. I will have to ask abou that.

@tomaae tomaae added the more info needed Need more information label Sep 7, 2022
@github-actions github-actions bot added the stale label Sep 22, 2022
@tomaae tomaae removed the stale label Sep 22, 2022
Repository owner deleted a comment from github-actions bot Sep 22, 2022
@github-actions github-actions bot added the stale label Oct 6, 2022
Repository owner deleted a comment from github-actions bot Oct 6, 2022
@tomaae tomaae added planned To be implemented in future release and removed stale labels Oct 6, 2022
@defaultsecurity
Copy link

you are talking about python there, not HA. I just had a look and HA knows date, timestamp and duration. Duration would be only one that is in such format, but it is defined as "fixed duration", so not sure. I will have to ask abou that.

I agree with the duration solution. I believe runtime should be passed in integer seconds. Then if the template sensor's "device_class" is "duration", most home assistant cards will display the duration in HH:MM:SS format automatically. History graphs are working as well. I tested it and it works, the card below gets its runtime data in seconds.

ups3

ups2

For those who cannot wait here is an example template script that converts the 1h30m30s format to seconds.

template:
  - sensor:
      - name: "UPS Runtime"
        unique_id: "5cfb7f04-d286-415e-a8bc-35c9007a4db8"
        device_class: "duration"
        unit_of_measurement: "s"
        state_class: "measurement"
        state: >
          {% set time = state_attr('binary_sensor.mikrotik_hex_ups', 'runtime_left') %}
          {% set seconds = 0 | int %}
          {% if 'd' in time %} {% set seconds = seconds + (time.split("d")[0]|int)*86400 %} {% set time = time.split("d")[1] %} {% endif %}
          {% if 'h' in time %} {% set seconds = seconds + (time.split("h")[0]|int)*3600 %} {% set time = time.split("h")[1] %} {% endif %}
          {% if 'm' in time %} {% set seconds = seconds + (time.split("m")[0]|int)*60 %} {% set time = time.split("m")[1] %} {% endif %}
          {% if 's' in time %} {% set seconds = seconds + (time.split("s")[0]|int) %} {% endif %}
          {{seconds}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request more info needed Need more information planned To be implemented in future release
Projects
None yet
Development

No branches or pull requests

3 participants