How to improve sensor?

Ah. It looks like this section of the templating docs might be relevant here: https://www.home-assistant.io/docs/configuration/templating/#processing-incoming-data

I believe the value_template would be something like

"{{ value_json['system']['L_ambient'] | int * 0.1 }}"

You’ll need to set the entity_id variable in the template sensor for that to work, otherwise Home Assistant won’t know what you’re referring to with that template.

I honestly have no idea if this will work since I’ve never done it before. I’m just hoping my interpretation of the docs along with the knowledge I do have about Home Assistant is correct here.

in the part ENTITY_ID THAT BEGINS WITH A NUMBER in https://www.home-assistant.io/docs/configuration/templating/#processing-incoming-data
the example is also like states.device_tracker['2008_gmc'] but this is not a nested dictionary :confused:

{{ state_attr('sensor.name', 'system') ['L_ambient'] }}

first see if this gets you the number
if so, then simply add the calculation of your liking

check here for reference: [SOLVED] Parsing a json value from an existing entity in a template sensor

1 Like

So you have this config and get the error you posted?

- platform: template
    sensors:
      oekofen_aussentemp:
        friendly_name: "some_friendly_name"
        value_template: '{{ (state_attr('sensor_name', 'system')["L_ambient"] | int) *0.1 | round(1) }}'
        unit_of_measurement: "°C"

The problem is the usage of the quotes

'{{ state_attr("oekofen", "system") ["L_ambient"] }}'

is looking good in the editor but throwing errors

Using your way {{ state_attr('sensor.name', 'system') ["L_ambient"] }} is missing the quotes and thus not working

Error: Testing configuration at /config
ERROR:homeassistant.util.yaml.loader:while parsing a block mapping
  in "/config/configuration.yaml", line 186, column 9
expected <block end>, but found '<scalar>'
  in "/config/configuration.yaml", line 187, column 42
Failed config
  General Errors: 
    - Error loading /config/configuration.yaml: while parsing a block mapping
  in "/config/configuration.yaml", line 186, column 9
expected <block end>, but found '<scalar>'
  in "/config/configuration.yaml", line 187, column 42

You are mixing quotes

The general rule should always be applied - double on the outside, single EVERYWHERE ELSE
I’m not shouting honest :smile:

You are right, Mutt. Question is: what would be the right quotes for nested dictionary parsing?

value_template: >
  {{ state_attr('sensor.name', 'system') ['L_ambient'] }}

use multi-line and dispense with the quoting issues
(sorry for the mixup of quotes in my example above, corrected them)

2 Likes

this version is throwing other errors but again messages from checking the config is more than one screen, so difficult to get to the firts line of the error

be sure to copy correctly, and not from the community posts. I can see incorrect curly quotes in your post, which are not accepted. Always type you own quotes…
what does the template show in the template editor?

1 Like

You are right, sorry for that. What about this:

- platform: template
    sensors:
      oekofen_aussentemp:
        friendly_name: "some_friendly_name"
        value_template: "{{ (state_attr('sensor.sensor_name', 'system')['L_ambient'] | int) *0.1 | round(1) }}"
        unit_of_measurement: "°C"

no curly quotes in my config… double checked.

off for some time now, will come back later

Looks good to me but I don’t have access to such an object to test.
I think you will just have to wait for the OP’s feedback

You and @Tediore (& Marius & the OP (I’d also like to thank, the producers, the make-up artists, my parents and of course the caterers :rofl: ) ) have done brilliantly so far, I’ve learnt a lot, thanks

1 Like

ok its just that I see this:

50 in your post quoting me :wink:

Id give this a try:

{{ (state_attr('sensor.sensor_name', 'system')['L_ambient']) |float /10 | round(2) }}
1 Like

Ehh… I don’t think I’ve actually been helpful this time around lol.

I did my best :crazy_face:

No the 10 will get rounded, you need a bracket

yes I stand corrected…:wink:
I moved the closing bracket because of the same reason one otherwise |int 's the ‘L_ambient’. Which in second view might be correct after all…

always difficult to keep the full view when not having the actual entity in the system yourself…

{{ ((state_attr('sensor.sensor_name', 'system')['L_ambient']) |float /10) | round(2) }}

which might be the same as

{{ (state_attr('sensor.sensor_name', 'system')['L_ambient'] |float /10) | round(2) }}

Hey I’m just shouting from the sidelines, you guys are doing the work.
I’m on my phone without a jinja interpreter so all I can do is cheer ! :rofl:

(and pass on my attempts at humour)

Please see the full data entity below. Maybe this can help in testing and many thanks to all supporters upfront!!
Ralf

{
   "system":{
      "system_info":"system global variables",
      "L_ambient":{"val":"104", "unit":"?C", "factor":"0.1", "min":"-32768", "max":"32767"},
      "L_errors":{"val":"0", "factor":"1", "min":"-32768", "max":"32767"},
      "L_usb_stick":{"val":"false", "format":"0:Aus|1:Ein"}
   },
   "weather":{
      "weather_info":"current weather data",
      "L_temp":{"val":"80", "unit":"?C", "factor":"0.1", "min":"-32768", "max":"32767"},
      "L_clouds":{"val":"75", "unit":"%", "factor":"1", "min":"-32768", "max":"32767"},
      "L_forecast_temp":{"val":"90", "unit":"?C", "factor":"0.1", "min":"-32768", "max":"32767"},
      "L_forecast_clouds":{"val":"87", "unit":"%", "factor":"1", "min":"-32768", "max":"32767"},
      "L_forecast_today":{"val":"true", "format":"0:Heute|1:Morgen"},
      "L_starttime":{"val":"910", "factor":"1", "min":"-32768", "max":"32767"},
      "L_endtime":{"val":"1500", "factor":"1", "min":"-32768", "max":"32767"},
      "L_source":{"val":"http://www.openweathermap.org", "length":"20"},
      "L_location":{"val":"Dieblich|Germany|2886968", "length":"20"},
      "cloud_limit":{"val":"55", "unit":"%", "factor":"1", "min":"0.0", "max":"100.0"},
      "hysteresys":{"val":"-40", "unit":"K", "factor":"0.1", "min":"-200.0", "max":"0.0"},
      "offtemp":{"val":"-100", "unit":"?C", "factor":"0.1", "min":"-300.0", "max":"200.0"},
      "lead":{"val":"120", "unit":"min", "factor":"1", "min":"0.0", "max":"600.0"},
      "refresh":{"val":"false"},
      "oekomode":{"val":"1", "format":"0:Aus|1:Ein"}
   },
   "forecast":{
      "forecast_info":"date|temp|cloud|speed|image|code|unit[|sunrise|sunset] code see https://openweathermap.org/weather-conditions",
      "L_w_0":{"val":"Mi, 27 Nov 09:20|8|75|26 km/h|10d|500|C|08:02|16:33", "length":"20"},
      "L_w_1":{"val":"Mi, 27 Nov 07:00|8|100|13 km/h|10n|500|C", "length":"20"},
      "L_w_2":{"val":"Mi, 27 Nov 10:00|9|100|11 km/h|10d|500|C", "length":"20"},
      "L_w_3":{"val":"Mi, 27 Nov 13:00|11|100|16 km/h|10d|500|C", "length":"20"},
      "L_w_4":{"val":"Mi, 27 Nov 16:00|9|100|12 km/h|10d|500|C", "length":"20"},
      "L_w_5":{"val":"Mi, 27 Nov 19:00|9|100|17 km/h|10n|500|C", "length":"20"},
      "L_w_6":{"val":"Mi, 27 Nov 22:00|9|100|18 km/h|10n|500|C", "length":"20"},
      "L_w_7":{"val":"Do, 28 Nov 01:00|10|100|22 km/h|10n|500|C", "length":"20"},
      "L_w_8":{"val":"Do, 28 Nov 04:00|9|100|25 km/h|10n|500|C", "length":"20"},
      "L_w_9":{"val":"Do, 28 Nov 07:00|9|100|20 km/h|10n|500|C", "length":"20"},
      "L_w_10":{"val":"Do, 28 Nov 10:00|9|100|22 km/h|10d|500|C", "length":"20"},
      "L_w_11":{"val":"Do, 28 Nov 13:00|9|100|23 km/h|10d|500|C", "length":"20"},
      "L_w_12":{"val":"Do, 28 Nov 16:00|9|99|18 km/h|10d|500|C", "length":"20"},
      "L_w_13":{"val":"Do, 28 Nov 19:00|8|100|16 km/h|10n|500|C", "length":"20"},
      "L_w_14":{"val":"Do, 28 Nov 22:00|8|100|13 km/h|10n|500|C", "length":"20"},
      "L_w_15":{"val":"Fr, 29 Nov 01:00|8|100|15 km/h|10n|500|C", "length":"20"},
      "L_w_16":{"val":"Fr, 29 Nov 04:00|8|100|15 km/h|10n|500|C", "length":"20"},
      "L_w_17":{"val":"Fr, 29 Nov 07:00|6|100|15 km/h|10n|500|C", "length":"20"},
      "L_w_18":{"val":"Fr, 29 Nov 10:00|5|100|15 km/h|10d|500|C", "length":"20"},
      "L_w_19":{"val":"Fr, 29 Nov 13:00|6|100|15 km/h|04d|804|C", "length":"20"},
      "L_w_20":{"val":"Fr, 29 Nov 16:00|5|92|14 km/h|04d|804|C", "length":"20"},
      "L_w_21":{"val":"Fr, 29 Nov 19:00|3|70|13 km/h|04n|803|C", "length":"20"},
      "L_w_22":{"val":"Fr, 29 Nov 22:00|2|0|10 km/h|01n|800|C", "length":"20"},
      "L_w_23":{"val":"Sa, 30 Nov 01:00|2|16|7 km/h|02n|801|C", "length":"20"},
      "L_w_24":{"val":"Sa, 30 Nov 04:00|2|93|6 km/h|10n|500|C", "length":"20"}
   },
   "hk1":{
      "hk_info":"heating circuit data",
      "L_roomtemp_act":{"val":"0", "unit":"?C", "factor":"0.1", "min":"-32768", "max":"32767"},
      "L_roomtemp_set":{"val":"235", "unit":"?C", "factor":"0.1", "min":"-32768", "max":"32767"},
      "L_flowtemp_act":{"val":"476", "unit":"?C", "factor":"0.1", "min":"-32768", "max":"32767"},
      "L_flowtemp_set":{"val":"482", "unit":"?C", "factor":"0.1", "min":"-32768", "max":"32767"},
      "L_comfort":{"val":"0", "unit":"K", "factor":"0.1", "min":"-32768", "max":"32767"},
      "L_state":{"val":"32", "factor":"1"},
      "L_statetext":"Heizbetrieb aktiv",
      "L_pump":{"val":"true", "format":"0:Aus|1:Ein"},
      "remote_override":{"val":"0", "unit":"K", "factor":"0.1", "min":"-32768", "max":"32767"},
      "mode_auto":{"val":"1", "format":"0:Aus|1:Auto|2:Heizen|3:Absenken"},
      "time_prg":{"val":"0", "format":"0:Zeit 1|1:Zeit 2"},
      "temp_setback":{"val":"160", "unit":"?C", "factor":"0.1", "min":"100.0", "max":"400.0"},
      "temp_heat":{"val":"235", "unit":"?C", "factor":"0.1", "min":"100.0", "max":"400.0"},
      "temp_vacation":{"val":"150", "unit":"?C", "factor":"0.1", "min":"100.0", "max":"400.0"},
      "name":{"val":"", "length":"20"},
      "oekomode":{"val":"3", "format":"0:Aus|1:Komfort|2:Minimum|3:?kologisch"},
      "autocomfort":{"val":"-1", "format":"0:Aus|1:Ein|2:Morgens|3:Abends"},
      "autocomfort_sunset":{"val":"0", "unit":"min", "factor":"1", "min":"-120.0", "max":"120.0"},
      "autocomfort_sunrise":{"val":"0", "unit":"min", "factor":"1", "min":"-120.0", "max":"120.0"}
   },
   "ww1":{
      "ww_info":"domestic hot water data",
      "L_temp_set":{"val":"350", "unit":"?C", "factor":"0.1", "min":"-32768", "max":"32767"},
      "L_ontemp_act":{"val":"829", "unit":"?C", "factor":"0.1", "min":"-32768", "max":"32767"},
      "L_offtemp_act":{"val":"829", "unit":"?C", "factor":"0.1", "min":"-32768", "max":"32767"},
      "L_pump":{"val":"false", "format":"0:Aus|1:Ein"},
      "L_state":{"val":"8200", "factor":"1"},
      "L_statetext":"Zeit au?erhalb Zeitprogramm|Anforderung Aus",
      "time_prg":{"val":"0", "format":"0:Zeit 1|1:Zeit 2"},
      "sensor_on":{"val":"0", "format":"0:WW|1:TPO|2:TPM|3:SpUnten"},
      "sensor_off":{"val":"0", "format":"0:WW|1:TPO|2:TPM|3:SpUnten"},
      "mode_auto":{"val":"1", "format":"0:Aus|1:Auto|2:Ein"},
      "mode_dhw":{"val":"1", "format":"0:Aus|1:Auto|2:Ein"},
      "heat_once":{"val":"false", "format":"0:Aus|1:Ein"},
      "temp_min_set":{"val":"400", "unit":"?C", "factor":"0.1", "min":"80.0", "max":"800.0"},
      "temp_max_set":{"val":"650", "unit":"?C", "factor":"0.1", "min":"80.0", "max":"800.0"},
      "name":{"val":"", "length":"20"},
      "smartstart":{"val":"0", "unit":"min", "factor":"1", "min":"0.0", "max":"90.0"},
      "use_boiler_heat":{"val":"0", "format":"0:Aus|1:Ein"},
      "oekomode":{"val":"0", "format":"0:Aus|1:Komfort|2:Minimum|3:?kologisch"}
   },
   "pe1":{
      "pe_info":"pellematic data",
      "L_temp_act":{"val":"735", "unit":"?C", "factor":"0.1", "min":"-32768", "max":"32767"},
      "L_temp_set":{"val":"700", "unit":"?C", "factor":"0.1", "min":"-32768", "max":"32767"},
      "L_ext_temp":{"val":"-32768", "unit":"?C", "factor":"0.1", "min":"-32768", "max":"32767"},
      "L_frt_temp_act":{"val":"1168", "unit":"?C", "factor":"0.1", "min":"-32768", "max":"32767"},
      "L_frt_temp_set":{"val":"80", "unit":"?C", "factor":"0.1", "min":"-32768", "max":"32767"},
      "L_br":{"val":"false", "format":"0:Aus|1:Ein"},
      "L_ak":{"val":"false", "format":"0:Aus|1:Ein"},
      "L_not":{"val":"true", "format":"0:Aus|1:Ein"},
      "L_stb":{"val":"true", "format":"0:Aus|1:Ein"},
      "L_modulation":{"val":"0", "unit":"%", "factor":"1", "min":"-32768", "max":"32767"},
      "L_uw_speed":{"val":"100", "unit":"%", "factor":"1", "min":"-32768", "max":"32767"},
      "L_state":{"val":"5", "format":"0:Dauerlauf|1:Start|2:Zuendung|3:Softstart|4:Leistungsbrand|5:Nachlauf|6:Aus|7:Saugen|8:! Asche !|9:! Pellets !|10:Pell Switch|11:St?rung|12:Einmessen|13:1|14:1|15:1|16:1|17:1|18:1|19:1|20:1|21:1|22:1|23:1|24:1|25:1|26:1|27:1|28:1|29:1|30:1|31:1|32:1|33:1|34:1|35:1|36:1|37:1|38:1|39:1|40:1|41:1|42:1|43:1|44:1|45:1|46:1|47:1|48:1|49:1|50:1|51:1|52:1|53:1|54:1|55:1|56:1|57:1|58:1|59:1|60:1|61:1|62:1|63:1|64:1|65:1|66:1|67:1|68:1|69:1|70:1|71:1|72:1|73:1|74:1|75:1|76:1|77:1|78:1|79:1|80:1|81:1|82:1|83:1|84:1|85:1|86:1|87:1|88:1|89:1|90:1|91:1|92:1|93:1|94:1|95:1|96:1|97:Aus|98:Aus|99:Aus|100:Aus|101:Aus"},
      "L_statetext":"Nachlauf",
      "L_type":{"val":"6", "format":"0:PE|1:PES|2:PEK|3:PESK|4:SMART V1|5:SMART V2|6:CONDENS|7:SMART XS|8:SMART V3|9:COMPACT|10:AIR"},
      "L_starts":{"val":"6376", "factor":"1"},
      "L_runtime":{"val":"6469", "unit":"h", "factor":"1"},
      "L_avg_runtime":{"val":"60", "unit":"min", "factor":"1"},
      "L_uw_release":{"val":"650", "unit":"?C", "factor":"0.1", "min":"-32768", "max":"32767"},
      "L_uw":{"val":"100", "unit":"%", "factor":"1", "min":"-32768", "max":"32767"},
      "L_storage_fill":{"val":"0", "unit":"kg", "factor":"1"},
      "L_storage_min":{"val":"400", "unit":"kg", "factor":"1", "min":"0.0", "max":"4000.0"},
      "L_storage_max":{"val":"6000", "unit":"kg", "factor":"1", "min":"150.0", "max":"30000.0"},
      "L_storage_popper":{"val":"0", "unit":"kg", "factor":"1", "min":"-32768", "max":"32767"},
      "storage_fill_today":{"val":"0", "unit":"kg", "factor":"1", "min":"-32768", "max":"32767"},
      "storage_fill_yesterday":{"val":"0", "unit":"kg", "factor":"1", "min":"-32768", "max":"32767"},
      "mode":{"val":"1", "format":"0:Aus|1:Auto|2:Ein"}
   },
   "error":{
   }
}