Energy consumption and Arlec Grid Connect (Tuya) smart plug

Hi all

Just thought this might help someone else. I have some Arlec branded “Smart Plug” devices that can monitor energy usage (for the Australians out there, they are about $20 from Bunnings). Rather than use the Grid Connect app I have added them into Smart Life and they appear in HA using both the Tuya and Tuya2 integrations. Only minor issue is although Smart Life tracks the energy usage, in HA they show the amount of W being used at the moment, but not the total kWh use over time. After some mucking around I found that literally all I needed to do was add the following into my configuration.yaml file:

  - platform: integration
    source: sensor.ty314159265666666666
    name: Main Fridge Energy
    unit_prefix: k
    round: 2

Where “sensor.ty314159265666666666” is the name of the sensor in tuya2 that directly shows the amount of W being consumed by the appliance plugged into the device. The unit_prefix and round settings converts the data to kWh, and the new sensor will start to log the energy being used over time. After testing your config then restarting the server, and some data has been collected, the new sensor should appear in the drop down options in the energy section configuration.

If you are still using the older Tuya integration, it will be a little more complex as you will likely need to create a sensor for that by using a template to grab the info out of the sensor attributes.

Info about this is here: Integration - Riemann sum integral - Home Assistant

4 Likes

Hey. Thank you so much for posting this. Okay so I have a relatively noobish question - where in the configuration.yaml do you add this piece of code?

I tried the code below but for some reason it is not working.

tuyav2: 
  - platform: integration
    source: sensor.ty314159265666666666
    name: Main Fridge Power Consumption
    unit_prefix: k
    round: 2

No problem. I have it in my sensors section eg:

sensor:
- platform: integration
    source: sensor.ty314159265666666666
    name: Main Fridge Energy
    unit_prefix: k
    round: 2

You will also need to change the sensor name to match yours eg the bit that says:

    source: sensor.ty314159265666666666

'cause, that doesn’t actually exist. :slight_smile:

Oh, this also all assumes that you have done all the necessary steps to enable tuya2 integration! Cheers.

Thanks! I’ve enabled tuya2, and it’s working nicely. Wanted to get the power consumption data as well.

How did you find the sensor name? I use the smartlife app (for added context) so I guess it’ll be brand agnostic?

Simples. Just go into configuration in Lovelace, find the integration, click on the devices hot link (in my case it shows I have 14!), find the device itself (it should have the same name you gave it in the Tuya/Smart Life app). Now you should see a card called entities that you can add straight into Lovelace. You can also click on the individual entities in the sample card and it will show the actual name in the entity id field - you will want the one with the “W” next to it. :wink:

1 Like

Hello, i have a smart plug that i can monitor in tuya app amd home assistant recognized it, but cannot get it to show consumption. I cannot integrate it as a sensor, because in home assistant it show as a switch and i have a single entity. Please give me an advice if you know a solution, i would really apreciate it.

If you haven’t migrated to tuya2 ie are still using the original tuya default integration, then you may be able to pull the data out of the attributes of the specific switch (you can see attributes of individual entities via developer tools in Lovelace) and put it into a new sensor eg something like:

      current_garage_fridge:
        friendly_name: "Garage Fridge Energy"
        entity_id: switch.thisisyourtuyaswitch
        unit_of_measurement: "W"
        device_class: energy
        value_template: "{{ state_attr('switch.thisisyourtuyaswitch', 'current_energy_w') }}"

Be aware that I don’t do this, so the code above is a guess so you will likely need to tweak it if you want to try this, but personally I’d suggest putting the effort into using tuya2 as it creates individual sensors for everything so it makes life easier, not to mention it seems faster plus all development work is going into tuya2 so the old integration will go end of life eventually… just saying… :wink:

Thank you, i had desabled tuya v2, because i have a lot to setup when moving to v2, but now i have to do it. I didn't now if it would recognize all of my sensors, but when i enebled it again i saw that it's all there, and then some. Now i have the motion sensor and de watt from the smart plug. Thanks for sharing your integration.

Quick update - with the rather sudden removal of the old Tuya integration, and moving the new Tuya integration into HA, my switches no longer provide energy statistics either as separate entities or within the attributes of the entity. No doubt this is on the roadmap, but if you are relying on this info you might want to hold off upgrading (at the very least keep the tuya2 integration via hacs running).

OK - seems that losing energy statistics is a bit of a bug. Checking the debug logs for tuya2 I can see that the data is being exposed to HA, it’s just not being parsed in properly. My guess is they left an old version of the script behind. An issue has been raised so hopefully this will be fixed soon.

FYI - apparently the code used in the tuya2 custom integration, and the official tuya2 integration are quite different hence the confusion and why some things worked in one but not the other, but the energy info as well as support for a lot more tuya devices will be coming soon.

1 Like

Update. As of HA 2021.11.0, three new sensors appeared for each energy switch. They were by default disabled, so just needed to enable them through the gui.

can you please be more specific? how and where can i do it
Thanks

From the Lovelace gui interface, go into Configuration, then Integrations, find the Tuya2 integration then click on the “devices” hyperlink. Now find the Tuya device you want to update. Click on that and you should see the three new sensors for current, power, and voltage that are disabled. Click on them and enable each by using the slider.

Thanks man is working like a charm :+1:t2:

2 Likes

Thanks for the tip.

It works well till the next HA restart.
Thanks!

After that, sensors are disabled again, and the icon is set back to the default (though changed manually by user, before HA restart).

Any usefull trick to fix this?

Odd. In theory, and for me in practise, they should stay enabled. Maybe just check to make sure you’re running the latest version(s) of everything… FWIW I’m currently on core-2021.11.4, supervisor-2021.10.8, and Home Assistant OS 6.6

Hello all,

have also integrated my Tuya sockets and Shelly’s with the ‘integration’ sensor into the energy dashboard. However, some values in the dashboard are not correct. I have in comparison between HomeAssstant and the SmartLife app sometimes very high differences. My waterbed should have consumed yesterday 2.44 kWh according to HA EnergyDashboard according to SmartLife it was only 0.78 kWh.

  - platform: integration
    source: sensor.wasserbettusb_power
    name: wasserbett_total_energy
    unit_prefix: k
    round: 2

Can it be that HomeAssistant updates the sensor only delayed? The same problem is also with motion detectors that are integrated with Zigbee…

Another idea might be to use ‘Utility Meter’ in HA, or to log the sensors with NodeRed via ‘power-monitor’.

Hi All

I have 2 energy monitoring plugs.
I can see the readouts in lovelace, but they don’t appear as devices on the "energy’ tab to calculate all the fun stuff like grid v solar usage.

Any way I can get this to work?

1 Like

Same for me, so what I needed to do was create a sensor using the ‘integration’ option eg in my sensor.yaml file I created a new sensor using the data being collected by the device. For example, if I have a switch that my gaming pc is plugged into that creates a device called “sensor.ty123456789012356789” that tracks the number of watts being consumed over time I would also need to create a sensor as follows:

  - platform: integration
    source: sensor.ty123456789012356789
    name: Gaming PC Energy
    unit_prefix: k
    round: 2

This “provides the Riemann sum of the values provided by a source sensor” - basically it samples the amount of watts being used at a specific point in time, and uses that to provide a fairly accurate estimate of the total amount of watts being used over a period of time. Then that is converted to kW with the ‘round 2’ setting.

Thanks for the reply! I think I’ve seen this somewhere before.

Where does the sensor name come from?

If I go into devices - office

I have this info.

Smart Plug with Energy Meter PC399HA (rrqlnfbld20erhk5)

by Tuya