Newbie - Trying to add/modify a valid configuration.yaml with a sensor and template

Hello, syntax error after add a sensor and template for my existant configuration.yaml.

Konfiguration failure!

Error loading /config/configuration.yaml: while scanning for the next token found character ‘\t’ that cannot start any token in “/config/configuration.yaml”, line 39, column 1

➜ config diff configuration.yaml configuration.yaml.bak
18c18
< sensor:

  • sensor:
    27c27
    < sensor:

  • sensor:
    36,60d35
    <
    <
    < - platform: command_line
    < name: power_balkon_pv_now
    < command: “curl http://192.168.178.26/status.html | grep -e “\var webdata_now_p” | cut -d’”’ -f 2"
    < unit_of_measurement: ‘W’
    < scan_interval: 60
    <
    < - platform: command_line
    < command: “curl http://192.168.178.26/status.html | grep -e “\var webdata_total_e” | cut -d’”’ -f 2"
    < name: power_balkon_pv_total
    < unit_of_measurement: ‘kWh’
    < scan_interval: 120
    <
    < sensor:
    < - platform: template
    < sensors:
    < extracted_data:
    < friendly_name: “balkon_pv_energy”
    < value_template: “{{ states(‘sensor.power_balkon_pv_total’) if states(‘sensor.power_balkon_pv_total’) | float > 0 }}”
    < unit_of_measurement: kWh
    < device_class: energy
    < state_class: total_increasing
    < unique_id: balkon_pv_energy
    <
    ➜ config

How should I successfully integrated the above sensor and template to my configuration.yaml?

Thanks for your feedback and support in advance?

The code you posted is formatted wrong. How did you get this code and did you post it here using the code tags? Just a quick glance and i see that you have double quotes in your double quotes. That wont work anyway:
command: “curl http://192.168.178.26/status.html | grep -e “\var webdata_now_p” | cut -d’”’ -f 2"
Will be read as “curl http://192.168.178.26/status.html | grep -e “ so the next character will be a \ and that will fail.

For reference:

1 Like

See the sticky post on code markup.

And see the FAQ about that error.

Thanks for the helpfull hints! Finaly I am using now the file editor with syntax check to edit my configuration.yaml.

The first part of the new added entries are now valid. But I still have a problem to add with valid syntax check the last part to my configuration.yaml. What could be the reason that the following lines are invalid?

sensor:
  - platform: template
    sensors:
      extracted_data:
        friendly_name: "balkon_pv_energy"
        value_template: {{ states('sensor.power_balkon_pv_total') if states('sensor.power_balkon_pv_total') | float > 0 }}
	unit_of_measurement: kWh
    	device_class: energy
    	state_class: total_increasing
    	unique_id: balkon_pv_energy

Thanks for your feedback and support in advance.

Try aligning unit_of_measurement with value_template

This for example is a working sensor format I have:

  - platform: template
    sensors:
      unmonitored_power:
        friendly_name: Unmonitored Power
        unique_id: Unmonitored_Power
        device_class: power
        unit_of_measurement: W
        value_template: "{{ (
        (states('sensor.legrand_consumo_totale_electricalmeasurement') | float(0))
        - (states('sensor.tutti_i_consumi_monitorati') | float(0))
        ) | float(0) | round(0)}}"

Also, I notice my value template start and ends with ", yours not.

value_template: {{ states('sensor.power_balkon_pv_total') if states('sensor.power_balkon_pv_total') | float > 0 }}

The single line template needs to be between quotes:
In this cast double qoutes outside.

value_template: "{{ states('sensor.power_balkon_pv_total') if states('sensor.power_balkon_pv_total') | float > 0 }}"