Local Tuya guide for complex devices

Hi there,

is there ANYWHERE a guide for me to add complex tuya devices? I found some threads but they all seem quite old and from what I can see, tuya local no longer supports yaml configs

My case: I want to add a Gosund SP112 to my local tuya network

  • That means switching the plug on/off (that works already)
  • Reading all the various power measurements (that works as text, but they are not recognized as power measurements per se?!?)
  • Switching the USB power on and off
  • And is there a way to calibrate the power measurements? I have a good power measurement device that I can use to calibrate the measurements on the plugs

Then the optional stuff that I would LIKE to control via local tuya somehow

  • setting the LED on the plugs
  • relay status in case of a power outage
  • child lock
  • swich overcharge

Any help is appreciated!

I have been meaning to do a guide on this since it is a bit tricky to do (and a few friends have asked for it).
How far though the localtuya setup are you? Have you added the device to the Tuya Smart mobile app? Have you setup the tuya iot developer account and project there?

I found the cloud api integration with local tuya didn’t work to discover devices for me (most likely due to the docker network my HA is on)

My rough workflow for setup is this:

  • Tuya Smart app - Create account and add the devices to it.

  • Tuya iot developer account - Follow the readme instructions here: GitHub - rospogrigio/localtuya: local handling for Tuya devices

  • Link devices - Part of above but has to be done each time a new device is added

  • Static IP - Giving the device a static IP will help with the integration since it uses IP

  • tuya-cli wizard - GitHub - TuyaAPI/cli: đź”§ A CLI for Tuya devices This cli command is how I get the localkey for my devices

  • tuya-cli get --id [id] --ip [ip] --protocol-version 3.3 --key [key] - This cli command will give you the current state of the devices dps (Id Value pairs that are used to setup the integration)

  • trial and error - This is the tedious part where it involves calling the above command, noting down the current status, making a change in the app (turning on/off 1 of the features) then calling the above command again to see which ID changed value then noting down the ID for later. Continue until you know the ID of all entities you want to configure.

  • Home Assistant integration - Now once the localtuya HACS integration is installed you can add a device with it here using the DeviceId, IP Address and Local Key. It will then prompt to setup the specific entities based on their type, match the type to the ID you want. (Make sure if oyu are adding more than 1 ID you deselect the “Do not add any more entities” checkbox otherwise it will end the device setup and only add 1 entity for you)

Hopefully this helps a bit.

1 Like

Thanks Damian for your guide so far!

  • created the account in the tuya smart app
  • created and linked the iot account
  • didn’t do the static IP yet, as I am just testing right now, but will do for the implementation
  • did not use the tuya cli as the local tuya cloud api works flawlessly
  • local tuya installed and device added

BUT I still have all the problems mentioned in my OP - power monitoring appears as an attribute, not as an actual power statistic - and most options are nonexistant. How do I configure those?

Thanks!

Ahh yes, for the power usage one there needs to be some special integration for Home Assistant to see it as a “real” power device. I haven’t done this myself, but I’ve seen it a few times.

Have a look at this integration: Integration - Riemann sum integral - Home Assistant

Basically, you set it up using the energy value as the source, see the example:

sensor:
  - platform: integration
    source: sensor.current_power
    name: energy_spent
    unit_prefix: k
    round: 2

I am replying here because I don’t know how to phrase the question that gets me an answer but I suspect you might know how todo what I want.

I have local tuya setup and I want to create a listng of all devices, their IP, their local key, and if possible the MAC ADDRESS. It should be available somewhere because when you try to edit a dive in local tuya it gives the friendly name the device id the local key and the IP but I would need to go through one by one to get that info.

Hey, I have 2 gang tuya switches and I can only setup one switch per device :frowning:

2 Likes

Hi Damien

Sorry for dragging up an old thread.

I’m at the trial and error stage.
I’ve got the IDs I want to change by adding the device then charging the options and deleting and readding it to the integration.

The problem I have is that one of the IDs won’t change via the integration & the other which is a true or false switch will only ever set itself to true even if I select false in HA.

Any advice to figure out where I’m going wrong?

I’m not too sure what the problem here is but I would say not everything in the integration is able to be changed, some of the properties might be read only.

Thanks

I did get the true/false one to work after a device reboot and removing and readding the device. But it would only work a few times before the state would change to unavailable until the device is rebooted.

Thankfully the toddler has lost interest in the buttons so automating the key lock on a timer is less of a pressing requirement now :rofl:

1 Like

Hi
Maybe I ask a stupid question but did you setup static IP to the tuya devices ?
Thanks for the help

you can set up a dedicated IP adress by reserving a static lease in your dhcp server configuration. On each device start, the dhcp server provides the same IP Address to the Tuya Device for the MAC Address.

thanks for clarification I reformulate to ensure I understood well : that means that once I know mac adress I should associate this mac with an IP on my router.

@FlyingKangaroo that’s correct. Associate an IP for each IoT Tuya device on the dhcp-server of your router/firewall.
Tuya devices always ask for an IP by dhcp on device boot. The dhcp-server will provide an dedicated (static) IP Address to the tuya device, if a static lease exists.
With static leases, a device will recieve everytime the same IP.

without static leases, the dhcp-server provides an IP out of the configured IP-Pool. It can be the same as before (when MAC address is known and lease time not expired), or any other IP (when lease were expired or MAC Address is unknown)