Tuya LOCAL with energy monitoring and without tuya-convert

Yeah, you need to add additional sensor entities to pull those values out. I think there’s an example in the readme (at least for one type of sensor).

1 Like

value_template: {{ state_attr(‘switch.yourtuya’, ‘voltage’) }}

1 Like

You can do it natively without having to clutter with additional template sensors directly in the integration.

One question is

device_class: current_consumption

no longer valid?
I had this

      - platform: sensor
        friendly_name: Plug 1 Power
        id: 19
        device_class: current_consumption

but get


Invalid config for [localtuya]: value is not allowed for dictionary value @ data['localtuya'][0]['entities'][2]['device_class']. Got 'current_consumption'
value is not allowed for dictionary value @ data['localtuya'][0]['entities'][2]['platform']. Got 'sensor'. (See /config/configuration.yaml, line 273).
1 Like

Yeah I was thinking the same. I’d leave this huge thread for questions, proposals or first-level support but would move issues-solving in new Issues posts and/or related PRss. So I’d ask @SmartM-ui and @juan11perez to continue with the discussion with their issues in the PRs created for them.
Agree?

1 Like

Use Device_class: power (unit kWh) / Device_class: energy (unit W) / Device_class: current (unit A) and Device_class: voltage (unit V) and Device_class: power_factor (unit Pf)

2 Likes

Hi all, I finally published a new release, v.3.0.0 that introduces:

  • asyncio in communication, with push updates: now status changes are immediate (also from physical buttons!)
  • persistent connection, instead of open-close connection; NOTE: some devices don’t support multiple connections, so it will not be possible to use Tuya app together with HA for those devices
  • (minor) brightness range remapping for light platform

Enjoy, and super thanks to @postlund for the amazing job !

6 Likes

THANK YOU!
Great job, you are SUPER

2 Likes

Sure! I agree.
Thanks again for the huge work

Strange issue, I installed everything with version 3.0, I have 2 identical smart sockets with energy monitoring, the first one configured it without problems, the second no this is the log:

File “/config/custom_components/localtuya/config_flow.py”, line 236, in async_step_basic_info
self.dps_strings = await validate_input(self.hass, user_input)
File “/config/custom_components/localtuya/config_flow.py”, line 178, in validate_input
interface.close()
UnboundLocalError: local variable ‘interface’ referenced before assignment

Ok, that’s an edge case bug when the connection fails. We should fix that.

See https://github.com/rospogrigio/localtuya-homeassistant/pull/88

Nice release! :sunglasses:
Thank you @rospogrigio and @postlund and all other people contributing!
Localtuya has become one of the best custom-component for HA…
If we then consider the spread of these products, it could also become one of the most useful of all…

:hugs: :partying_face:

2 Likes

Hi guys,

I was able to create the sensors for the energy monitoring on my power plug, but what I noticed is that they stop updating on the HA when I close the TuyaSmart App on my phone, and to double check I removed my smartplug from my app and the sensors became “unavailable”. Do you guys think it’s something with my power plug or something wrong that I did during the setup?

My plug is one of this https://pt.aliexpress.com/item/4000001152724.html?spm=a2g0s.9042311.0.0.2742b90abKgC2f

If you guys need more details, let me know!

You can register your tuya device on the tuya api website
https://github.com/codetheweb/tuyapi/issues/22
which will reveal your device local_key and device_id.
That will mean you won’t need to rely on the cloud service at all.

Thanks Robb! You opened my eyes to the part where I get the local_key, I only did the fast way to get the keys from this link https://github.com/codetheweb/tuyapi/blob/fc0eb599444ff7d129ddd3e76fbad3e5bb2c16a8/docs/SETUP.md, but giving another look at the instructions, it seens that in this way im relying on the smart plug registered on my device, but under the “Linking a Tuya device with Smart Link” (that I didn’t followed) it seens like I will not need the smart plug registered on my phone to work. I’ll give it a shot tomorrow and give an update here.

Hope it works well for you. There is a bit involved in the process but satisfying when you get that code and can move forward free of the cloud.

We have an issue open about this:

Guys,

To give an update, I followed the instructions under “Linking a Tuya device with Smart Link” on this link https://github.com/codetheweb/tuyapi/blob/fc0eb599444ff7d129ddd3e76fbad3e5bb2c16a8/docs/SETUP.md and now it’s working without the smart plug being connected to the App on my Phone.

When it was connected to my phone and the TuyaSmart app was open on the energy monitoring screen, the updates on the sensors in the HA were almost instant, now without the phone I noticed that it takes 10~20 seconds to update what still amazing for my purpose!

Thanks a lot guys.

Just to share with you, I’m using the smart plug to check if my RF Ceiling Fans are on or off to update it state on HA so I can turn on the Fans with the RF control and be able to also turn off with Alexa for example.

My fans came with RF remotes from it’s own brand, so I basically bought some spare controls for each fan and hardwired their buttons to relays connected to the raspberry pi GPIO and created switches on the HA to control it, and the Emulated Hue to connect with Alexa. The problem I was facing is that if I turned the fans on with Alexa and turned off with the RF control, for the HA the fans were still considered on.

Now I mapped all the currents measured by the smart plug in the sensors on HA from the fans diferente speed levels and with it’s lights turned on and off to know and update their correct states on HA almost real time.

If anyone is interest to know more about it I would be glad to help.

(I tried to use tasmota with the sonoff rf bridge to control the fans with it, but it didn’t work so thats why I went to the hardwire approach :P)

Hi all,

I’m trying to connect my Tuya (Kogan Branded) power consumption meters.

Does anyone know the repo to add to HACS I haven’t been able to find it anywhere.

Thanks very much,

  • Brock