The library used by the new Tuya HA component is tuyapy (tuyapy · PyPI). 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.
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.
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?
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…
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.
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?
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…
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?
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:
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.