How to improve sensor?

Burningstone, you are right. “system” is a dictionary itself"

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

Line 187 is the one with the value_template

Color coding in ide 9 is also showing that some " ’ … are wrong

Not sure, can’t say I’ve done that before. @RalfP can you post a screenshot of the state attributes of that entity in Developer Tools > States? Something like this:

This is the “full” sensor

this is the template sensor

To get the value of 11.6 just divide the 116 by 10

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