I have ~12 TP-Link switches and outlets (HS100 and HS200) set up, added to HASSIO via the Integrations section rather than manually in the configuration.yaml file. I have avoided the manual config (i.e. listing all the IPs + names) method mostly due to this comment though I do not know if this is true. I would like to get them working as sensors so I can use the sensor outputs as triggers for various things.
I have copied the template sensor configuration directly from here, changing out the placeholder switch name for my own (switch.island) which is a HS200.
Iām aware of the issue (though not a solution) for TP Link devices periodically becoming unavailable, as discussed in this Git issue/thread, but believe this is a separate issue because according to its history, this particular switch (switch.island) rarely experiences this āunavailableā issue.
Here is my set up:
Template Sensor config:
sensor:
- platform: template
sensors:
my_tp_switch_amps:
friendly_name_template: "{{ states.switch.island.name}} Current"
value_template: '{{ states.switch.island.attributes["current_a"] | float }}'
unit_of_measurement: 'A'
my_tp_switch_watts:
friendly_name_template: "{{ states.switch.island.name}} Current Consumption"
value_template: '{{ states.switch.island.attributes["current_power_w"] | float }}'
unit_of_measurement: 'W'
my_tp_switch_total_kwh:
friendly_name_template: "{{ states.switch.island.name}} Total Consumption"
value_template: '{{ states.switch.island.attributes["total_energy_kwh"] | float }}'
unit_of_measurement: 'kWh'
my_tp_switch_volts:
friendly_name_template: "{{ states.switch.island.name}} Voltage"
value_template: '{{ states.switch.island.attributes["voltage"] | float }}'
unit_of_measurement: 'V'
my_tp_switch_today_kwh:
friendly_name_template: "{{ states.switch.island.name}} Today's Consumption"
value_template: '{{ states.switch.island.attributes["today_energy_kwh"] | float }}'
unit_of_measurement: 'kWh'
Relevant Error Logs:
Could not render template my_tp_switch_amps: UndefinedError: 'mappingproxy object' has no attribute 'current_a'
6:45 AM components/template/sensor.py (ERROR)
Could not render template my_tp_switch_volts: UndefinedError: 'mappingproxy object' has no attribute 'voltage'
6:45 AM components/template/sensor.py (ERROR)
Could not render template my_tp_switch_watts: UndefinedError: 'mappingproxy object' has no attribute 'current_power_w'
6:45 AM components/template/sensor.py (ERROR)
Could not render template my_tp_switch_total_kwh: UndefinedError: 'mappingproxy object' has no attribute 'total_energy_kwh'
6:45 AM components/template/sensor.py (ERROR)
Could not render template my_tp_switch_today_kwh: UndefinedError: 'mappingproxy object' has no attribute 'today_energy_kwh'
6:45 AM components/template/sensor.py (ERROR)