Help with template sensor!

Hello!
I am trying without success get the consumption data from Daikin AC.
With this link http://192.168.0.98/aircon/get_week_power I get this:

ret=OK,today_runtime=1376,datas=0/200/200/300/300/200/300

Where each number in datas the consumption of every day of the week (in 0,1 kWh values)

With this link ttp://192.168.0.98/aircon/get_day_power_ex?days=2 I get this:
ret=OK,curr_day_heat=3/2/1/3/1/2/2/2/4/3/4/3/3/3/4/4/3/2/2/3/2/3/2/0,prev_1day_heat=3/3/2/3/3/2/3/3/2/3/3/2/2/3/4/4/5/1/2/3/1/3/3/2,curr_day_cool=0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0,prev_1day_cool=0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0

" the power consumption (in 0.1 kWH) of the last 2 days, separated hour by hour starting from midnight and also separated for cooling and heating." Explanation from Github.

My question is: Is possible to make a sensor of daily consumption?

I made some test and it didnt work.

Thank you in advance.

Copy and paste your return value in Dev tools/Templates and then you can experiment with it.

{% set value = 'ret=OK,today_runtime=1376,datas=0/200/200/300/300/200/300' %}
{{ value.split(',')[2].split('=')[1].split('/')[0] }}

This returns the first value of datas: 0,

{{ value.split(',')[2].split('=')[1].split('/')[0] }}

the second 200, and so on.

Same for the second return value:

{% set value = 'ret=OK,curr_day_heat=3/2/1/3/1/2/2/2/4/3/4/3/3/3/4/4/3/2/2/3/2/3/2/0,prev_1day_heat=3/3/2/3/3/2/3/3/2/3/3/2/2/3/4/4/5/1/2/3/1/3/3/2,curr_day_cool=0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0,prev_1day_cool=0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0' %}
{{ value.split(',')[1].split('=')[1].split('/')[0] }}

Returns the first number of ‘curr_day_heat’

{{ value.split(',')[1].split('=')[1].split('/')[1] }}

the second.

Now you have something to play with. :slightly_smiling_face:

EDIT: Here is some other explanation about splitting.

1 Like

THANK YOU VERY MUCH!

I was totally lost. Now I can begin to play with something. Maybe now it will be possible to get :slight_smile:

Best regards :)))

I was making some tests before sleep and it works!
Again
 Thank you very much! I was really lost :slight_smile: Its good go to sleep after solve that.

  -  platform: rest
 resource: http://192.168.0.98/aircon/get_day_power_ex
 name: "0Daikin1"
 value_template: >
  {{ ((float(value.split(',')[1].split('=')[1].split('/')[0])
   +  float(value.split(',')[1].split('=')[1].split('/')[1]) 
   +  float(value.split(',')[1].split('=')[1].split('/')[2])
   +  float(value.split(',')[1].split('=')[1].split('/')[3])
   +  float(value.split(',')[1].split('=')[1].split('/')[4])
   +  float(value.split(',')[1].split('=')[1].split('/')[5])
   +  float(value.split(',')[1].split('=')[1].split('/')[6])
   +  float(value.split(',')[1].split('=')[1].split('/')[7])
   +  float(value.split(',')[1].split('=')[1].split('/')[8])
   +  float(value.split(',')[1].split('=')[1].split('/')[9])
   +  float(value.split(',')[1].split('=')[1].split('/')[10])
   +  float(value.split(',')[1].split('=')[1].split('/')[11])
   +  float(value.split(',')[1].split('=')[1].split('/')[12])
   +  float(value.split(',')[1].split('=')[1].split('/')[13])
   +  float(value.split(',')[1].split('=')[1].split('/')[14])
   +  float(value.split(',')[1].split('=')[1].split('/')[15])
   +  float(value.split(',')[1].split('=')[1].split('/')[16])
   +  float(value.split(',')[1].split('=')[1].split('/')[17])
   +  float(value.split(',')[1].split('=')[1].split('/')[18])
   +  float(value.split(',')[1].split('=')[1].split('/')[19])
   +  float(value.split(',')[1].split('=')[1].split('/')[20])
   +  float(value.split(',')[1].split('=')[1].split('/')[21])
   +  float(value.split(',')[1].split('=')[1].split('/')[22])
   +  float(value.split(',')[1].split('=')[1].split('/')[23])) ) /10 | float }}
 unit_of_measurement: "kWh"

Ouch, that is quite ugly. Why not aggregate with sum?

So your value_template becomes:

{{ value.split(',')[1].split('=')[1].split('/')|map('float')|sum/10 }}

And this is the value_template for cool:

{{ value.split(',')[3].split('=')[1].split('/')|map('float')|sum/10 }}
1 Like

Thank you very much for your answer.
Yes, it looks nicer. I will try :slight_smile:

Definitely I have to learn about template!

1 Like

Or a bit hardened version :wink::

value_template for cool:

{{ value.split('curr_day_cool=')[1].split(',')[0].split('/') | map('float') | sum() / 10 }}

value_template for heat:

{{ value.split('curr_day_heat=')[1].split(',')[0].split('/') | map('float') | sum() / 10 }}

Nice one!

This is going to be replaced with real support in 0.111 though.

1 Like

is it already supported by plugin or do I have to create custom sensor to track consumption?

Is there a plan to deliver the consumption in a total increasing entity, so this can be integrated in the energy model from HA directly?