I do my first steps with Hass, so I would like to ask: How can I use the value from Energy Monitoring in my Home Assistant Dashboard?
You need to create a Template sensor, reading the appropriate attribute. My TP-Link HS110 (EU) provides the following attributes with respect to energy:
- current_power_w
- total_energy_kwh
- voltage
- current_a
- today_energy_kwh
Template sensor in configuration.yaml could be (adjust the entity_id value switch.hs110-1
):
sensor:
- platform: template
sensors:
current_power_w:
friendly_name: "Current Power (Watts)"
unit_of_measurement: 'w'
value_template: "{{ state_attr('switch.hs110-1', 'current_power_w') | float }}"
Then, add this sensor to your UI, using a sensor card.
As an alternative, you could simply add an Entity card to the UI, it supports selecting an entity’s attribute (instead of it’s state). However, you can only display the current value, no history, no graph.
Thank you, are these values also availiable and how I have to change the code?
# TP Link Steckdose
switch_steckdose1_ampere:
friendly_name_template: "{{ states.switch.steckdose1.name}} Strom"
value_template: '{{ states.switch.steckdose1.attributes["current_a"] | float }}'
unit_of_measurement: 'A'
switch_steckdose1_watt:
friendly_name_template: "{{ states.switch.steckdose1.name}} Leistung"
value_template: '{{ states.switch.steckdose1.attributes["current_power_w"] | float }}'
unit_of_measurement: 'W'
switch_steckdose1_total_kwh:
friendly_name_template: "{{ states.switch.steckdose1.name}} Gesamtverbrauch"
value_template: '{{ states.switch.steckdose1.attributes["total_energy_kwh"] | float }}'
unit_of_measurement: 'kWh'
switch_steckdose1_volt:
friendly_name_template: "{{ states.switch.steckdose1.name}} Volt"
value_template: '{{ states.switch.steckdose1.attributes["voltage"] | float }}'
unit_of_measurement: 'V'
switch_steckdose1_heute_kwh:
friendly_name_template: "{{ states.switch.steckdose1.name}} Tagesverbrauch"
value_template: '{{ states.switch.steckdose1.attributes["today_energy_kwh"] | float }}'
unit_of_measurement: 'kWh'
The Smartphone App Kasa shows me current power of 49 W, in the sensor card 0 W > I have waited some time…do you have an idea?
I found the mistake, I used the word name for steckdose1
Hi All - I have a similar issue with a KP115 and HA which is driving me nuts
In summary - I have the app on the phone AND an entity card in HA that is reporting non-zero values for current usage (see below). The entity card appears to be querying the attributes for the device correctly - they are non zero as shown below.
So far so good. May challenge comes when I want to use thse values (I’m focusing on just one at the moment) in a sensor card but it only ever shows 0 . I’m assuming that the breaks in the graph line are from when I’ve restarted my server to process any YAML changes
Talking of yaml here are my current settings.
tplink:
discovery: true
switch:
- host: 192.168.0.143
sensor:
-
- platform: template*
- sensors:*
-
kp115_gr_01_current_power_w:*
-
friendly_name: "Current Power (Watts)"*
-
unit_of_measurement: 'w'*
-
value_template: "{{ state_attr('switch.kp115-gr-01', 'current_power_w') | float }}"*
If anyone can advise what I am doing wrong I will be your friend for life
Hi Dave,
You mentioned you have several devices … I have 4 of these, and soon found that using lovelace entity cards took a lot of space to display, when I really just wanted a compact summary. I spent time fiddling with Frontend cards from HACS, and came up with:
The column alignment is annoying, but as a newbie it does the job for now. It uses a combination of HACS frontend layout-card, mini-graph-card and several multiple-entity-row components. Happy to post my lovelace card configuration code if you like.
FYI, the HS110 and KP115 are not currently used, so showing zeroes. I also found that naming the switches with sensible names, they quickly became tedious and confusing, so renamed the permanent switches and had to manually change all the references.
Hi all,
Got some issues with my Kasa HS110 on HA - the energy monitoring attributes are totally off. I am running firmware 1.1.1 (re-enabled for HA). Any idea what’s going on?
Would you mind sharing how you made this graph?
The graph part uses the mini-graph-card custom component installed in HACS … so if you haven’t already, install the wonderful (but unofficial) HACS integration (see this Home Assistant community thread
I should say firstly that I had previously copied/pasted/adapted the following into my configuration.yaml file as part of setting my HS110 switches to report energy usage.
# Extracting Energy Sensor data from the TP-Link HS-110 units
# Note: Hassio has picked up the friendly name from the Kasa phone app (where it is easy to change)
# Note: the HS110 or KP115 is a "switch" device, but we are both formatting the attributes and presenting them as sensors
#
sensor tp-link_switch1:
- platform: template
sensors:
hs110_amps:
friendly_name_template: "{{ state_attr('switch.HS110','friendly_name') }} Current"
value_template: "{{ state_attr('switch.HS110','current_a') | float }}"
unit_of_measurement: "A"
hs110_watts:
friendly_name_template: "{{ state_attr('switch.HS110','friendly_name') }} Current Consumption"
value_template: "{{ state_attr('switch.HS110','current_power_w') | float }}"
unit_of_measurement: "W"
hs110_total_kwh:
friendly_name_template: "{{ state_attr('switch.HS110','friendly_name') }} Total Consumption"
value_template: "{{ state_attr('switch.HS110','total_energy_kwh') | float }}"
unit_of_measurement: "kWh"
hs110_volts:
friendly_name_template: "{{ state_attr('switch.HS110','friendly_name') }} Voltage"
value_template: "{{ state_attr('switch.HS110','voltage') | float }}"
unit_of_measurement: "V"
hs110_today_kwh:
friendly_name_template: "{{ state_attr('switch.HS110','friendly_name') }} Today's Consumption"
value_template: "{{ state_attr('switch.HS110','today_energy_kwh') | float }}"
unit_of_measurement: "kWh"
sensor tp_link_switch2:
- platform: template
sensors:
fridge_amps:
friendly_name_template: "{{ state_attr('switch.fridge','friendly_name') }} Current"
value_template: "{{ state_attr('switch.fridge','current_a') | float }}"
unit_of_measurement: "A"
fridge_watts:
friendly_name_template: "{{ state_attr('switch.fridge','friendly_name') }} Current Consumption"
value_template: "{{ state_attr('switch.fridge','current_power_w') | float }}"
unit_of_measurement: "W"
fridge_total_kwh:
friendly_name_template: "{{ state_attr('switch.fridge','friendly_name') }} Total Consumption"
value_template: "{{ state_attr('switch.fridge','total_energy_kwh') | float }}"
unit_of_measurement: "kWh"
fridge_volts:
friendly_name_template: "{{ state_attr('switch.fridge','friendly_name') }} Voltage"
value_template: "{{ state_attr('switch.fridge','voltage') | float }}"
unit_of_measurement: "V"
fridge_today_kwh:
friendly_name_template: "{{ state_attr('switch.fridge','friendly_name') }} Today's Consumption"
value_template: "{{ state_attr('switch.fridge','today_energy_kwh') | float }}"
unit_of_measurement: "kWh"
… and so on for my other switches. I started off giving all switches long meaningful names, but they got unweildy so I have permanently allocated switches to my chest freezer (down in the garage) and fridge and re-installed them with shorter names.
When HACS is installed, you can go to the HACS tab in Home Assistant and select “Frontend”. Now locate the “mini-graph-card”. Clicking [INFORMATION] or the card’s name will open a documentation page, so you can get an idea about the card before installing it. You will want to come back to this information to try out the many many options
Install mini-graph-card and reload.
In the Home Assistant > Overview tab (aka lovelace), edit dashboard, [+ Add card], and (at the bottom of the list of card types) you should select the “Custom: Mini Graph Card” entry. If the Card Configuration pop-up window isn’t giving you any options, click on [Show Code editor] to see
1| type: custom:mini-graph-card
2|
where you can start entering the configuration options.
I spent quite a while trying out some of the many options provided by this card … and ended up with my lovelace card configuration being:
type: custom:mini-graph-card
icon: mdi:server
title: Energy Consumption
line_width: 1
smoothing: false
points_per_hour: 10
entities:
- sensor.hs110_watts
- sensor.kp115_watts
- sensor.fridge_watts
- sensor.chestfreezer_watts
show:
icon: false
name: false
state: false
labels: true
Try moving your cursor over the different sensor labels, clicking a sensor label, then clicking the title of the pop-up window to expand it.
Hi Borez,
Wow, those figures are crazy. I assume you have done the power off/pause/power on cycle with both the HS110 unit and your HA server ?
I have 2 HS110 units:
one has Firmware: 1.0.5 Build 200917 Rel.095346 on Hardware version 4.0
other has Firmware 1.5.7 Build 191125 Rel. 105256 on Hardware version 2.0
Sorry I don’t feel competent to help debug, because it took me a fair bit of fiddling to get it working, and I don’t really understand the details
I have HS110 HW 4.0 FW 1.0.5 and my energy sensors within Homeassistant no longer show any values. It used to work.
My configuration of config.yml looks like this:
sensor:
- platform: template
sensors:
computer_switch_amps:
friendly_name_template: "{{ state_attr('switch.computer','friendly_name') }} Current"
value_template: "{{ state_attr('switch.computer','current_a') | float }}"
unit_of_measurement: "A"
computer_switch_watts:
friendly_name_template: "{{ state_attr('switch.computer','friendly_name') }} Current Consumption"
value_template: "{{ state_attr('switch.computer','current_power_w') | float }}"
unit_of_measurement: "W"
computer_switch_total_kwh:
friendly_name_template: "{{ state_attr('switch.computer','friendly_name') }} Total Consumption"
value_template: "{{ state_attr('switch.computer','total_energy_kwh') | float }}"
unit_of_measurement: "kWh"
computer_switch_volts:
friendly_name_template: "{{ state_attr('switch.computer','friendly_name') }} Voltage"
value_template: "{{ state_attr('switch.computer','voltage') | float }}"
unit_of_measurement: "V"
computer_switch_today_kwh:
friendly_name_template: "{{ state_attr('switch.computer','friendly_name') }} Today's Consumption"
value_template: "{{ state_attr('switch.computer','today_energy_kwh') | float }}"
unit_of_measurement: "kWh"
3d_drucker_switch_amps:
friendly_name_template: "{{ state_attr('switch.3d_drucker','friendly_name') }} Current"
value_template: "{{ state_attr('switch.3d_drucker','current_a') | float }}"
unit_of_measurement: "A"
3d_drucker_switch_watts:
friendly_name_template: "{{ state_attr('switch.3d_drucker','friendly_name') }} Current Consumption"
value_template: "{{ state_attr('switch.3d_drucker','current_power_w') | float }}"
unit_of_measurement: "W"
3d_drucker_switch_total_kwh:
friendly_name_template: "{{ state_attr('switch.3d_drucker','friendly_name') }} Total Consumption"
value_template: "{{ state_attr('switch.3d_drucker','total_energy_kwh') | float }}"
unit_of_measurement: "kWh"
3d_drucker_switch_volts:
friendly_name_template: "{{ state_attr('switch.3d_drucker','friendly_name') }} Voltage"
value_template: "{{ state_attr('switch.3d_drucker','voltage') | float }}"
unit_of_measurement: "V"
3d_drucker_switch_today_kwh:
friendly_name_template: "{{ state_attr('switch.3d_drucker','friendly_name') }} Today's Consumption"
value_template: "{{ state_attr('switch.3d_drucker','today_energy_kwh') | float }}"
unit_of_measurement: "kWh"
badezimmer_waschmaschine_switch_amps:
friendly_name_template: "{{ state_attr('switch.badezimmer_waschmaschine','friendly_name') }} Current"
value_template: "{{ state_attr('switch.badezimmer_waschmaschine','current_a') | float }}"
unit_of_measurement: "A"
badezimmer_waschmaschine_switch_watts:
friendly_name_template: "{{ state_attr('switch.badezimmer_waschmaschine','friendly_name') }} Current Consumption"
value_template: "{{ state_attr('switch.badezimmer_waschmaschine','current_power_w') | float }}"
unit_of_measurement: "W"
badezimmer_waschmaschine_switch_total_kwh:
friendly_name_template: "{{ state_attr('switch.badezimmer_waschmaschine','friendly_name') }} Total Consumption"
value_template: "{{ state_attr('switch.badezimmer_waschmaschine','total_energy_kwh') | float }}"
unit_of_measurement: "kWh"
badezimmer_waschmaschine_switch_volts:
friendly_name_template: "{{ state_attr('switch.badezimmer_waschmaschine','friendly_name') }} Voltage"
value_template: "{{ state_attr('switch.badezimmer_waschmaschine','voltage') | float }}"
unit_of_measurement: "V"
badezimmer_waschmaschine_switch_kwh:
friendly_name_template: "{{ state_attr('switch.badezimmer_waschmaschine','friendly_name') }} Today's Consumption"
value_template: "{{ state_attr('switch.badezimmer_waschmaschine','today_energy_kwh') | float }}"
unit_of_measurement: "kWh"
badezimmer_trockner_switch_amps:
friendly_name_template: "{{ state_attr('switch.badezimmer_trockner','friendly_name') }} Current"
value_template: "{{ state_attr('switch.badezimmer_trockner','current_a') | float }}"
unit_of_measurement: "A"
badezimmer_trockner_switch_watts:
friendly_name_template: "{{ state_attr('switch.badezimmer_trockner','friendly_name') }} Current Consumption"
value_template: "{{ state_attr('switch.badezimmer_trockner','current_power_w') | float }}"
unit_of_measurement: "W"
badezimmer_trockner_switch_total_kwh:
friendly_name_template: "{{ state_attr('switch.badezimmer_trockner','friendly_name') }} Total Consumption"
value_template: "{{ state_attr('switch.badezimmer_trockner','total_energy_kwh') | float }}"
unit_of_measurement: "kWh"
badezimmer_trockner_switch_volts:
friendly_name_template: "{{ state_attr('switch.badezimmer_trockner','friendly_name') }} Voltage"
value_template: "{{ state_attr('switch.badezimmer_trockner','voltage') | float }}"
unit_of_measurement: "V"
badezimmer_trockner_switch_today_kwh:
friendly_name_template: "{{ state_attr('switch.badezimmer_trockner','friendly_name') }} Today's Consumption"
value_template: "{{ state_attr('switch.badezimmer_trockner','today_energy_kwh') | float }}"
unit_of_measurement: "kWh"
Is it the same for someone?
does this still work?