HS110 Get energy information as sensors for InfluxDB

Energy

I can see the switches, turn them off, and even see their wattage but I want them to be individual sensors that will report to influxdb like my fitbit, or anything else that is a sensor does.

How do you break those watts, voltage, amps etc out as individual sensors?

tplink:
  discovery: true
  #light:
  #  - host: 192.168.200.1
  #  - host: 192.168.200.2
  switch:
    - host: 192.168.1.188
    - host: 192.168.1.189
 # dimmer:
 #   - host: 192.168.200.5
 #   - host: 192.168.200.6
 # strip:
 #   - host: 192.168.200.7
 #   - host: 192.168.200.8

#Entertainment Switch
sensor:
  - platform: template
    sensors:
      device_tracker.hs110_2_amps:
        friendly_name_template: "{{ states.switch.device_tracker.hs110_2.name}} Current"
        value_template: '{{ states.switch.device_tracker.hs110_2.attributes["current_a"] | float }}'
        unit_of_measurement: 'A'
      device_tracker.hs110_2_watts:
        friendly_name_template: "{{ states.switch.device_tracker.hs110_2.name}} Current Consumption"
        value_template: '{{ states.switch.device_tracker.hs110_2.attributes["current_power_w"] | float }}'
        unit_of_measurement: 'W'
      device_tracker.hs110_2_total_kwh:
        friendly_name_template: "{{ states.switch.device_tracker.hs110_2.name}} Total Consumption"
        value_template: '{{ states.switch.device_tracker.hs110_2.attributes["total_energy_kwh"] | float }}'
        unit_of_measurement: 'kWh'
      device_tracker.hs110_2_volts:
        friendly_name_template: "{{ states.switch.device_tracker.hs110_2.name}} Voltage"
        value_template: '{{ states.switch.device_tracker.hs110_2.attributes["voltage"] | float }}'
        unit_of_measurement: 'V'
      device_tracker.hs110_2_today_kwh:
        friendly_name_template: "{{ states.switch.device_tracker.hs110_2.name}} Today's Consumption"
        value_template: '{{ states.switch.device_tracker.hs110_2.attributes["today_energy_kwh"] | float }}'
        unit_of_measurement: 'kWh'
        
             



#Server Switch	
sensor:
  - platform: template
    sensors:
      device_tracker.hs110_amps:
        friendly_name_template: "{{ states.switch.device_tracker.hs110.name}} Current"
        value_template: '{{ states.switch.device_tracker.hs110.attributes["current_a"] | float }}'
        unit_of_measurement: 'A'
      device_tracker.hs110_watts:
        friendly_name_template: "{{ states.switch.device_tracker.hs110.name}} Current Consumption"
        value_template: '{{ states.switch.device_tracker.hs110.attributes["current_power_w"] | float }}'
        unit_of_measurement: 'W'
      device_tracker.hs110_total_kwh:
        friendly_name_template: "{{ states.switch.device_tracker.hs110.name}} Total Consumption"
        value_template: '{{ states.switch.device_tracker.hs110.attributes["total_energy_kwh"] | float }}'
        unit_of_measurement: 'kWh'
      device_tracker.hs110_volts:
        friendly_name_template: "{{ states.switch.device_tracker.hs110.name}} Voltage"
        value_template: '{{ states.switch.device_tracker.hs110.attributes["voltage"] | float }}'
        unit_of_measurement: 'V'
      device_tracker.hs110_today_kwh:
        friendly_name_template: "{{ states.switch.device_tracker.hs110.name}} Today's Consumption"
        value_template: '{{ states.switch.device_tracker.hs110.attributes["today_energy_kwh"] | float }}'
        unit_of_measurement: 'kWh'
1 Like

This is what I use and it’s been working fine for quite a while :+1:

  1. I defined the switch manually
    - platform: tplink
      host: 192.168.7.63
      name: PumpPlug

  1. Then I extract the value - very similar to what you do in terms of the template, but from the switch, not from the device_tracker.
    tp_link1_amps:
      value_template: '{{ states.switch.pumpplug.attributes["current_a"] | replace(" A", "") | float }}'
      unit_of_measurement: 'A'
      friendly_name: Amps (Pump)
  1. And this is what I see in http://raspberrypi.local:8123/developer-tools/state
    image
1 Like

can i see how this is in your config yaml? Its making my home assistant go into safe mode. also is this all you have or do you have my code plus this? or do i erase my code and just use yours?

What is the error message that comes up when you run it through a config check?

Ill try it again. but before i do should i erase my settings and use yours or am I supposed to use my settings and yours?

Before restarting, use the config check under configuration / server controls.

image

If you’re using the built in InfluxDB integration for Home Assistant, attributes are already available as data in InfluxDB.

1 Like

Just added you three to this. I don’t have that button and I think I have to make something clear, I’m running this on Unraid using https://hub.docker.com/r/homeassistant/home-assistant/

Should I be using something else for Unraid? I’m seeing solutions online that I don’t even have options for. @chairstackercode doesn’t look like mine but I’m using the official way. Just kind of confusing.

@swiftlyfalling I did the official Influxdb https://www.home-assistant.io/integrations/influxdb/, I know there are built in ones I can choose from but Influx is not on the list when I press setup new intergration.

I am also using the Docker version of Home Assistant Core.

InfluxDB is not configurable through the Integration Setup UI. You have to configure it with YAML. So you and I are using the same InfluxDB Integration.

All attributes of an entity are available as fields under a measurement named the same as the entity in InfluxDB, unless you deviated from the recommended configuration as listed on the doc page you linked to.

I’d recommend looking at the data you have already in InfluxDB and then writing template sensors for anything that’s missing, though, as I said before, for me anyway, everything is already there unless I’ve specifically excluded it.

My setup is pretty standard, with only one addition that won’t affect this:

influxdb:
  host: influxdb.default.svc.cluster.local
  username: !secret influx_user
  password: !secret influx_pass
  database: "homeassistant"
  tags:
    source: hass
1 Like

Yep below is my Yaml. Let me know if I’m crapping the bed here but it works fine.

The problem is my HS110 just has switch functions of off and on. Even when i try to add a gauge to Lovelace theres no option for current wattage or anything else, unless I’m missing it?

My fitbit information is all being tracked and an option in influxdb no problem. I can also easily add it to my front page. Its just the Hs110 that I can only see it on the switch itself.

#influxDB
influxdb:
  host: 192.168.1.98
  port: 8086
  database: HASS
  #username: MY_USERNAME
  #password: MY_PASSWORD
  ssl: false
  verify_ssl: false
  max_retries: 3
  default_measurement: state
  #exclude:
  #  entities:
   #    - entity.id1
   #    - entity.id2
   # domains:
   #    - automation
  #include:
   # entities:
   #    - entity.id3
   #    - entity.id4
  tags:
    instance: prod
    source: hass

Then I think you have something broken with the HS110. I have 4 HS110’s in my home, and all of them appear as switches in Home Assistant and all of them have the following attributes:

current_power_w
total_energy_kwh
voltage
current_a
today_energy_kwh

And all of those attribute are visible in InfluxDB.

1 Like

You are correct! I used your influxdb yaml and it’s there! Thanks a lot. I don’t know what was wrong with mine but I can now get power in my Grafana from home assistant.

One last question for you. If I wanted to make a little widget on my Lovelace using attributes, current wattage etc, how do you do that? I am just seeing sensors.

The Entity Card supports displaying an attribute:

2 Likes

Can I add this card as a manual entry via the GUI?

When I use the example from the link you provided I end up with an error: Unknown entity type: entity

It’s probably just another spacing issue but I can’t figure it out.