Adding LocalTuya power monitor plugs to the Energy Dashboard


In a recent update the Localtuya team have been able to get the power monitoring working for a large amount of Tuya based plusg and switches which support power monitoring without the need for the Tuya app to be open.

I currently have 3 different brand plugs which are single smart plugs with power monitoring. I won’t cover adding them in to Home Assistant as there a plenty of guides out already but you will need to have the power consumption attribute enabled on the switch. This is normally one of the gpio’s on the plug which you will need to work out which it is. One it’s set up you should see the attributes for power consumption when you view it in developer tools.

Switch
Localtuya switch config for Arlec PC191HA Single Plug with Energy Monitoring

To expose the consumption to the Energy Dashboard you will need 2 Sensors, The first based of the current_consumption attribute with a device_class set and a total consumption sensor. Add the following to your configuration.yaml and restart. Obviously substitute your device details in for mine.

template:
  - sensor:
      - name: "Dishwasher Power Consumption"
        unit_of_measurement: "W"
        state: >
   {{state_attr('switch.dishwasher_switch','current_consumption'
)}}
        device_class: power

This will add a senor called sensor.dishwasher_power_consumption it should look like this in developer tools.

sensor:
  - platform: integration
    source: sensor.dishwasher_power_consumption
    name: Dishwasher Power Total

This is your total sensor called sensor.dishwasher_power_total and will look like this. it is calculated using Reimann sum integral calculation found here.

An important value is device_class: energy without that you will not be able to add it to your energy dashboard.

Providing you have completed that successfully you can proceed to add it to the energy dashboard.

Dashboard configuration

The final Energy Dashboard.