I’m needing a little help on a template to separate one sensor into two.
This data is how long is available on the utility - Gas/Electric. Electric: 18 Hours left Gas: 74 days, 17 hours left
as you can see, everything is separated by a comma.
So sometimes the format might be
Electric | Gas
days,hours, separate, days,hours
hours, separate, days,hours
hours, separate, hours
days,hours, separate, hours
From this, I’m wanting two new sensors Electirc_Expt: (how many days/hours are remaining) Gas_Expt: (how many days/hours are remaining)
I should have seen that… it’s not a real list, it’s a list-shaped string. That makes the template a little more involved because you have to filter out all the extraneous characters. There’s probably an easier way to do this, but I think the following should work:
template:
- sensor:
- name: "Electric Expt"
state: >
{% set x = states('utilita_test_dates') %}
{%- set x = ((x | replace(","," ") | replace("]","")
| replace("[","") | replace("'","")).split('left')) %}
{{x[0] | replace(' ', ', ') }}
- name: "Gas Expt"
state: >
{% set x = states('utilita_test_dates') %}
{%- set x = ((x | replace(","," ") | replace("]","")
| replace("[","") | replace("'","")).split('left')) %}
{{ x[1] | replace(' ', ', ') }}