MementoMori
(Lukas Mauracher)
February 3, 2021, 10:08pm
1
Hello, i tried difference ways to add the energy data from my 2 TP Link HS110 Plugs.
But i always get an error. Im very new in Linux, Raspberry and Home Assistant.
Below my Config file. i know there are much same Topics but i tried all and cant get it to work.
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
# Text to speech
tts:
- platform: google_translate
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
# Sensors
sensors:
### TPLINK HS110 Power Consumption ###
-platform: template
### TPLINK - Plug 1 ###
plug1_amps:
friendly_name_template: "{{ states.switch.plug1.name}} Current"
value_template: '{{ states.switch.plug1.attributes["current_a"] | float }}'
unit_of_measurement: 'A'
plug1_watts:
friendly_name_template: "{{ states.switch.plug1.name}} Current Consumption"
value_template: '{{ states.switch.plug1.attributes["current_power_w"] | float }}'
unit_of_measurement: 'W'
plug1_total_kwh:
friendly_name_template: "{{ states.switch.plug1.name}} Total Consumption"
value_template: '{{ states.switch.plug1.attributes["total_energy_kwh"] | float }}'
unit_of_measurement: 'kWh'
plug1_volts:
friendly_name_template: "{{ states.switch.plug1.name}} Voltage"
value_template: '{{ states.switch.plug1.attributes["voltage"] | float }}'
unit_of_measurement: 'V'
plug1_today_kwh:
friendly_name_template: "{{ states.switch.plug1.name}} Today's Consumption"
value_template: '{{ states.switch.plug1.attributes["today_energy_kwh"] | float }}'
unit_of_measurement: 'kWh'
### TPLINK - Plug 2 ###
plug2_amps:
friendly_name_template: "{{ states.switch.plug2.name}} Current"
value_template: '{{ states.switch.plug2.attributes["current_a"] | float }}'
unit_of_measurement: 'A'
plug2_watts:
friendly_name_template: "{{ states.switch.plug2.name}} Current Consumption"
value_template: '{{ states.switch.plug2.attributes["current_power_w"] | float }}'
unit_of_measurement: 'W'
plug2_total_kwh:
friendly_name_template: "{{ states.switch.plug2.name}} Total Consumption"
value_template: '{{ states.switch.plug2.attributes["total_energy_kwh"] | float }}'
unit_of_measurement: 'kWh'
plug2_volts:
friendly_name_template: "{{ states.switch.plug2.name}} Voltage"
value_template: '{{ states.switch.plug2.attributes["voltage"] | float }}'
unit_of_measurement: 'V'
plug2_today_kwh:
friendly_name_template: "{{ states.switch.plug2.name}} Today's Consumption"
value_template: '{{ states.switch.plug2.attributes["today_energy_kwh"] | float }}'
unit_of_measurement: 'kWh'
### TPLink Smart Switch Totals ###
tp_link_watts_total:
value_template: >-
{%- if not is_state("sensor.plug1_watts","unknown") -%}
{{ ((states.sensor.plug1_watts.state | float) + (states.sensor.plug2_watts.state | float)) | round(2) }} {%- endif -%}
friendly_name: 'Current Consumption'
unit_of_measurement: 'W'
tp_link_total_kwh:
value_template: >-
{%- if not is_state("sensor.plug1_total_kwh","unknown") -%}
{{ ((states.sensor.plug1_total_kwh.state | float) + (states.sensor.plug2_total_kwh.state | float)) | round(2) }} {%- endif -%}
friendly_name: 'Total Consumption'
unit_of_measurement: 'kWh'
tp_link_today_kwh:
value_template: >-
{%- if not is_state("sensor.plug1_today_kwh","unknown") -%}
{{ ((states.sensor.plug1_today_kwh.state | float) + (states.sensor.plug2_today_kwh.state | float)) | round(2) }} {%- endif -%}
friendly_name: 'Todays Consumption'
unit_of_measurement: 'kWh'
it’s an indentation problem. Instead of this:
sensors:
### TPLINK HS110 Power Consumption ###
-platform: template
Try this
sensors:
### TPLINK HS110 Power Consumption ###
- platform: template
1 Like
MementoMori
(Lukas Mauracher)
February 4, 2021, 11:18am
3
Hello, thanks i tried it before. Now i get this log.
2021-02-04 12:17:45 ERROR (SyncWorker_3) [homeassistant.util.yaml.loader] while parsing a block mapping
in "/config/configuration.yaml", line 17, column 5
expected <block end>, but found '<block mapping start>'
in "/config/configuration.yaml", line 19, column 6
2021-02-04 12:17:45 ERROR (MainThread) [homeassistant.components.homeassistant] Error loading /config/configuration.yaml: while parsing a block mapping
in "/config/configuration.yaml", line 17, column 5
expected <block end>, but found '<block mapping start>'
in "/config/configuration.yaml", line 19, column 6
check my setup
it is working fine for me
1 Like
MementoMori
(Lukas Mauracher)
February 4, 2021, 11:25am
5
with one plug in the Config all is working great. But i have two plugs and this dont want to work.
Either the second Plug will be ignored or i get the error messages.
could it be that you have an issue with the indentation of the tp_link_watts_total sensors? seems they are not in the same line as the plug sensors
MementoMori
(Lukas Mauracher)
February 4, 2021, 11:38am
7
Can you share you full Config file? i copy and paste yours in my config and chanced the switch names but i get this error again. Maybe my config is broken?
2021-02-04 12:36:37 ERROR (SyncWorker_11) [homeassistant.util.yaml.loader] while parsing a block mapping
in "/config/configuration.yaml", line 3, column 1
expected <block end>, but found '<block mapping start>'
in "/config/configuration.yaml", line 16, column 3
2021-02-04 12:36:37 ERROR (MainThread) [homeassistant.components.homeassistant] Error loading /config/configuration.yaml: while parsing a block mapping
in "/config/configuration.yaml", line 3, column 1
expected <block end>, but found '<block mapping start>'
in "/config/configuration.yaml", line 16, column 3
Foxxy
(Reps)
February 4, 2021, 11:42am
8
Plug 1 is one sensor, plug 2 another
Add before plug 2:
- platform: template
sensors:
tp_power2_amps:
Best, JR
1 Like
duceduc
February 4, 2021, 11:43am
9
since you are adding the code to the config file, you need to add sensor
at the very top.
sensor:
- platform: template
sensors:
hs110_amps:
friendly_name_template: "HS110 Aktuelle Stromstärke"
value_template: '{{ states.switch.wifi_steckdose.attributes["current_a"] | float }}'
unit_of_measurement: 'A'
icon_template: mdi:clipboard-pulse-outline
hs110_watts:
friendly_name_template: "HS110 Aktuelle Leistung"
value_template: '{{ states.switch.wifi_steckdose.attributes["current_power_w"] | float }}'
unit_of_measurement: 'W'
icon_template: mdi:clipboard-pulse-outline
hs110_total_kwh:
friendly_name_template: "HS110 Gesamtverbrauch"
value_template: '{{ states.switch.wifi_steckdose.attributes["total_energy_kwh"] | float }}'
unit_of_measurement: 'kWh'
icon_template: mdi:clipboard-pulse-outline
hs110_volts:
friendly_name_template: "HS110 Aktuelle Spannung"
value_template: '{{ states.switch.wifi_steckdose.attributes["voltage"] | float }}'
2 Likes
MementoMori
(Lukas Mauracher)
February 4, 2021, 11:53am
11
Thanks you all helped me. Now both Plugs are working
sensor:
- platform: template
sensors:
hs110_amps:
friendly_name_template: "HS110 Aktuelle Stromstärke"
value_template: '{{ states.switch.plug1.attributes["current_a"] | float }}'
unit_of_measurement: 'A'
icon_template: mdi:clipboard-pulse-outline
hs110_watts:
friendly_name_template: "HS110 Aktuelle Leistung"
value_template: '{{ states.switch.plug1.attributes["current_power_w"] | float }}'
unit_of_measurement: 'W'
icon_template: mdi:clipboard-pulse-outline
hs110_total_kwh:
friendly_name_template: "HS110 Gesamtverbrauch"
value_template: '{{ states.switch.plug1.attributes["total_energy_kwh"] | float }}'
unit_of_measurement: 'kWh'
icon_template: mdi:clipboard-pulse-outline
hs110_volts:
friendly_name_template: "HS110 Aktuelle Spannung"
value_template: '{{ states.switch.plug1.attributes["voltage"] | float }}'
- platform: template
sensors:
hs110_2amps:
friendly_name_template: "HS110 Aktuelle Stromstärke"
value_template: '{{ states.switch.plug2.attributes["current_a"] | float }}'
unit_of_measurement: 'A'
icon_template: mdi:clipboard-pulse-outline
hs110_2watts:
friendly_name_template: "HS110 Aktuelle Leistung"
value_template: '{{ states.switch.plug2.attributes["current_power_w"] | float }}'
unit_of_measurement: 'W'
icon_template: mdi:clipboard-pulse-outline
hs110_2total_kwh:
friendly_name_template: "HS110 Gesamtverbrauch"
value_template: '{{ states.switch.plug2.attributes["total_energy_kwh"] | float }}'
unit_of_measurement: 'kWh'
icon_template: mdi:clipboard-pulse-outline
hs110_2volts:
friendly_name_template: "HS110 Aktuelle Spannung"
value_template: '{{ states.switch.plug2.attributes["voltage"] | float }}'
Yep, “sensor:” was missing