Tuya switches with energy monitoring support


#1

Great to finally have official support for Tuya switches.

I have two of these switches and they are working great.

Is it possible to add energy monitoring support functionality to this component? (Like Wemo Insight?)

My two switches both support energy monitoring via the Tuya app.


Tuya Integration
#2

Hey there, where abouts can you buy those switches? Specially the ones with energy monitoring.


#3

This is the exact one I have.


#4

I’m about to purchase a Tuya / Smart Life plug which has power monitoring. This is the main reason I need it. Is it possible this will be supported?


#5

Hopefully, someone will pick this up.


#6

Appearantly it already outputs all the data to the logs https://github.com/sean6541/tuya-homeassistant/issues/16
I really hope someone will integrate this to HA.


#7

That tuya-homeassistant project is using python-tuya (https://github.com/clach04/python-tuya) to directly control the switches over the local network. Unfortunately it looks like that method requires extracting a localKey for each device, which is not trivial (the methods seem to include “redirect the traffic from the device and use Wireshark to intercept a request” or using a rooted Android phone to get it from the config files of an app).

The library used by the new Tuya HA component is tuyapy (https://pypi.org/project/tuyapy/). It seems to be published by Tuya themselves and doesn’t seem to be on GitHub. It hits an endpoint at 'https://px1.tuya{}.com/homeassistant/skill'.format(SESSION.region) which apparently, at least for plugs, returns a JSON payload that includes only online and state keys.

I also have a TP Link plug, for which the HA component exposes the power monitoring values as entity attributes. It uses local network control, which has advantages (no remote dependency or exposure) and disadvantages (no automatic discovery), but in the case of Tuya components the localKey thing seems to make switching the component to local control a non-starter (obviously individuals can do it as a custom_component, but it wouldn’t be reasonable to have the standard Tuya component setup instructions include rooting your phone or sniffing all your network traffic). So it seems like we’re at the mercy of Tuya Inc. to add the power monitoring values to the API and expose them on the device class in tuyapy.


#8

If I am able to extract the keys from the Tuya devices, can I use the tuya-homeassistant to monitor power on the plugs?
I have no trouble extracting the keys, but I understand why it is not a great solution for everyone.


#9

I am sorry, I did not understand clearly.
I’ve recently got a smart plug usable with SmartLife app but also with Tuya one.
So I’ve added it in HomeAssistant.
It works great, but unfortunately I cannoy see energy consumption.
Is there any way to see it?

Thanks in advance


#10

We need tuya to support is I guess…based on what I’m reading…


#11

I’m confused. So is there any way to get the Power usage from this in home assistant? I’ve got the tuya component running now and can see and control the switch…
I’ve got this so I can tell when the tumbledryer is finsihed… it would be nice to have HA let me know, rather than also have to use the Tuya app on my phone for that…

Thanks!


#12

There is no clear path to solving this problem without a few parties doing additional work. Bottom line: If you use the Tuya HA component, it communicate with the Tuya cloud server which, at present, does not return the energy values in the payload. If you communicated locally with the Tuya devices, the energy value are indeed returned in the payload. (See post from KlassH Aug 19, above) However, there is no code that I can find that decodes them on github. You must follow the procedure to extract the keys before you can talk locally to the devices. I wrote a custom python script to decode the energy value and put them into an ASCII file so they can be transferred to HA and subsequently used as sensor data.


#13

Hello there Klaas…
so let’s say that I have the localkey for my tuya smart plug, what should I exactly have to add to configuration.yaml to use the plug without Tuya cloud and getting power consumption?

Thanks in advance!


#14

@CapitanCatarro

I tried the localkey method. When I tried it, it did not support energy monitoring although it was being worked on. The more annoying part for me is that it seems to conflict with Google Assistant controlling the switches…


#15

I use etekcity vesync outlets for monitoring energy usage. Haven’t had a problem yet and fully integrates with HA.

https://www.amazon.com/Etekcity-Monitoring-Required-Warranty-Lifetime/dp/B06XSTJST6/ref=sr_1_5?keywords=etekcity&qid=1552356872&s=hi&sr=1-5


#16

Hello,

What do you mean by fully integrate? Can you see energy usage on HA? If so, what app are you using on the outlets and what platform on HA? Or how did under it up?


#17

The outlets come with vesync firmware that you connect to your wifi and the vesync app. The HA component comes with daily energy usage and current power. The switch entity has the state attributes current_power_w and today_energy_kwh which you can use a template to access such as:

sensor:
  - platform: template
    sensors:
      outlet_a:
        friendly_name: "Outlet A"
        value_template: "{{(states.switch.outlet_a.attributes|default(0)).current_power_w|round(2)}}"
        unit_of_measurement: "W"

#18

Ok that’s great but these aren’t using Tuya platform then…


#19

I have a kogan monitoring plug (AU)
Yes, HA can not retrieve the power usage details
BUT with Node Red the node-red-contrib-tuya-smart node can read them …
refer https://flows.nodered.org/node/node-red-contrib-tuya-smart
the major difference in setting up the node is you are required to provide the Device ID and
Device Key refer https://github.com/codetheweb/tuyapi/blob/master/docs/SETUP.md

would it been possible to allow HA to accept these details for the power monitor ??

In the meantime, i will find a way to write these figures back into HA from Node Red

LeeB


#20

Perhaps converting them to use Tasmota would allow you to grab the power usage etc directly…? I’m in Aus too so would be interested to know if it’s possible. Using the system I linked also means no more cloud dependency.