Converts TUYA and ZigBee devices interface to Shelly interface. Used for integration to SunnyHome.
309
This software converts TUYA and ZigBee devices interface to Shelly interface. Can handle local (LAN) or cloud TUYA interface. ZigBee devices are handled via Zigbee2MQTT https://www.zigbee2mqtt.io/ Project was created mainly for integration of other devices to SunnyHome (snyll/sunnyhome), because SunnyHome handles only Shelly devices.
Important note for TUYA local mode:
Many Tuya devices do not work properly in Local mode do not handle multiple commands sent in quick succession.
Some will reboot, possibly changing state in the process,
others will go offline for 30s to a few minutes if you overload them.
there is some rate limiting to try to avoid this, but it is not sufficient for many devices,
and may not work across entities where you are sending commands to multiple entities on the same device.
The rate limiting also combines commands, which not all devices can handle.
The exact timing depends on the device.
and probably many more...
For first use and testing, I recommend to use Tuya-cloud, then Tuya-local if needed.
Preconditions for TUYA:
Access ID ,Access Secret and DeviceId - How to do it, for example, here https://clusterm.github.io/tuyanet/Local IP address of device in your home networkPreconditions for ZigBee:
/dev/ttyUSB0)
or Get Local IP address of ZigBee gateway device in your home networkIEEE address e.g. 0xa5b158e28109c984 or Friendly NameTested ZigBee adapters with ZigBee2Mqtt:
Home assistant SkyConnect USB
https://rpishop.cz/usb-brany/5665-home-assistant-skyconnect-usb.html
Connect the device to the Raspberry and find out what device name (in my case /dev/ttyUSB0).
The device name can be found in the /dev directory or after connection with the dmesg command. The listing will be something like:
cp210x 1-1.2:1.0: cp210x converter detected
usb 1-1.2: cp210x converter now attached to ttyUSB0
Snippet example of my Zigbee2MQTT config file configuration.yaml
permit_join: true
mqtt:
base_topic: zigbee2mqtt
server: mqtt://192.168.1.160:1883
keepalive: 60
reject_unauthorized: false
version: 4
serial:
adapter: ezsp
port: /dev/ttyUSB0
frontend:
port: 8080
Mapping device to docker requires to add parameter for docker run command:
--device=/dev/ttyUSB0:/dev/ttyUSB0
Example of docker run command:
docker run -p 8080:8080 --restart unless-stopped --name zigbee2mqtt -v /opt/zigbee2mqtt-data/:/app/data/ --device=/dev/ttyUSB0:/dev/ttyUSB0 -d koenkk/zigbee2mqtt
Find out the IP address on the home router and then enter it in the configuration (e.g. 192.168.1.198).
Snippet example of my Zigbee2MQTT config file configuration.yaml
permit_join: true
mqtt:
base_topic: zigbee2mqtt
server: mqtt://192.168.1.160:1883
keepalive: 60
reject_unauthorized: false
version: 4
serial:
adapter: ezsp
port: tcp://192.168.1.198:8888
frontend:
port: 8080
SmartHomeConverter Installation:
Note: change platform to amd64 if needed
Create a directory for the configuration file eg /opt/smarthomeconverter/config
Download and run docker run -p 8801:8801 --rm --name smarthomeconverter --platform=linux/arm64/v8 -v /opt/smarthomeconverter/config/:/app/config/ -d dododuke/smarthomeconverter:arm64
For automatic start after reboot add parameter --restart unless-stopped
The default configuration file smarthomeconverter.json will be created in given path eg /opt/smarthomeconverter/config if not found
Edit and save configuration file smarthomeconverter.json. (Restart docker to load the new configuration file docker restart smarthomeconverter)
For configuration details, see chapter Configuration.
Now the application should run on https://your-ip:8801, for example if your-ip is 192.168.0.1, got to the URL
http://192.168.0.1:8801/app/status
or if you want to see more details go to http://192.168.0.1:8801/app/status?detail=true
It shows a device and switch table status.
SmartHomeConverter Updating:
docker stop smarthomeconverter
docker rm smarthomeconverter
docker pull dododuke/smarthomeconverter:arm64
and then again the main run command eg:
docker run -p 8801:8801 --rm --name smarthomeconverter --platform=linux/arm64/v8 -v /opt/smarthomeconverter/config/:/app/config/ -d dododuke/smarthomeconverter:arm64
For automatic start after reboot add parameter --restart unless-stopped
Configuration file smarthomeconverter.json
Edit config file smarthomeconverter.json
Enter then Tuya device Access ID , Access Secret, DeviceId, Local IP, and LocalKey to the config. If you don't know LocalKey for Tuya device, leave it empty. It will be downloaded automatically from the Cloud. Then, you can copy it from web table
http://192.168.0.1:8801/app/status?detail=true
and paste to the config file. Then the Cloud won't be contacted for local keys. Each time the device is deleted and re-registered to the Cloud, the LocalKey changes.
or for ZigBee, Enter then ZigBee device information Protocol, DeviceId , Local IP, and LocalPort to the config.
{
"DebugLevelFrom": 0,
"DebugLevelTo": 8,
"MaxLogHistory": 1000,
"Devices": [
{
"Id": "MyShelly",
"Name": "My Virtual Shelly",
"Active": true,
"Protocol": "ShellyPro3",
"LocalIp": "",
"LocalPort": 8801
},
{
"Id": "MyTuya",
"Name": "My thermostat",
"Active": true,
"Protocol": "TUYA-local",
"AccessId": "yyyyyyyyyyyyyyyyyyyy",
"ApiSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"DeviceId": "zzzzzzzzzzzzzzzzzzzzzz",
"LocalKey": "",
"Version": "3.3",
"Region": "CentralEurope",
"LocalIp": "192.168.1.123",
"LocalPort": 0
},
{
"Id": "MyZigBeeSocket",
"Name": "Socket in kitchen",
"Active": true,
"DeviceId": "0xa5b158e28109c984",
"LocalIp": "192.168.1.160",
"LocalPort": 1883,
"Protocol": "ZigBee2Mqtt"
}
],
"Map": [
{
"Pin1": {
"DeviceId": "MyShelly",
"Switch": "0"
},
"Pin2": {
"DeviceId": "MyTuya",
"Switch": "1",
"SwitchName": "switch",
"TemperatureName": [
"upper_temp"
],
"TemperatureFactor": 0.5,
"CurrentName": [
"cur_current",
"18"
],
"CurrentFactor": 0.001,
"PowerName": [
"cur_power",
"19"
],
"PowerFactor": 0.1,
"VoltageName": [
"cur_voltage",
"20"
],
"VoltageFactor": 0.1,
"EnergyName": [
"",
""
],
"EnergyFactor": 0.1
}
},
{
"Pin1": {
"DeviceId": "MyShelly",
"Switch": "3"
},
"Pin2": {
"DeviceId": "MyZigBeeSocket",
"Switch": "1"
}
}
]
}
Configuration JSON description
DebugLevelFrom - minimum level of information for logging
DebugLevelTo - maximum level of information for logging
MaxLogHistory - number of lines for log history
Devices array - array of devices. Must contain at least one virtual Shelly.
Id - device unique identification e.g. MyShellyName - device friendly name (for display)Active - true for active device, if false, device is ignoredProtocol - allowed values are:
ShellyPro3 - for Shelly deviceShellyPro4PM - for device which can measure Power valueShelly1PMPlus - for device which can measure Power valueTUYA-local - for TUYA device controlled locally over the LANTUYA-cloud - for TUYA device controlled over the CloudTUYA - for TUYA device controlled locally and - if it fails - then over cloudZigBee2Mqtt - for ZigBee devices over MQTTAccessId - access id for Tuya, can be obtained as described abovezigbee2mqttApiSecret - Api secret id for Tuya, can be obtained as described aboveDeviceId - id of the specific TUYA device, can be obtained as described aboveIEEE address e.g. 0xa5b158e28109c984 or Friendly Name e.g. Kitchen socket 1LocalKey - local key for device controlled over the LAN (not required for the cloud devices). Can be obtained as described above. If it is empty, it will be automatically dowloaded from the Cloud.Version - version of Tuya protocol. The most common is 3.3. Version 3.4 is not tested yet (not required for the cloud devices).Region - the region of the Tyua Cloud that you have chosen in your Cloud account (not required for the local devices). A valid value can take on only one of these values China,WesternAmerica,EasternAmerica,CentralEurope,WesternEurope,IndiaLocalIp - local (LAN) IP address of your device (not required for the cloud devices).LocalPort - optional - local (LAN) port of your device (not required for the cloud devices). Can be 0 for automatic port selection (6668).1883RateLimit - optional - can be 0 - the minimum time in milliseconds for which the device is polled. The number of device queries can be limited (especially for problematic local devices). Queries to status of device that will be more frequent than this interval will not be performed or they will be loaded from the cache.WaitAfterConnect - optional - can be 0 - the time in milliseconds to wait after connecting a device to start communication (especially for problematic local devices).PermanentConnection - optional - default is false - indicates whether the connection to the device should be maintained permanently (especially for problematic local devices).MessageTimeout - optional - message timeout in milliseconds for ZigBee, default is 8000Map array - array of pin pairs. A pin map that tells how individual device pins (switches) will map to virtual Shelly switches.
Pin1 - pin of virtual Shelly
DeviceId - The virtual Shelly device Id to which the pin relatesSwitch - The virtual Shelly device switch (relay) number - usually starting from 0Pin2 - pin of real (Tuya) device
DeviceId - The real (Tuya, ZigBee) device Id to which the pin relates from Devices sectionSwitch - The real (Tuya, ZigBee) device switch number - usually starting from 1Other ZigBee parameters are automatically obtained from MQTT, but can be entered manually.
Other TUYA parameters depends on device and can be found on Tuya cloud account in device details or here https://developer.tuya.com/en/docs/iot/product-standard-function-introduction?id=K9tp15ceh63gr
SwitchName - device switch name - usually switch or switch_1, or for device with more switches switch_2 etc.CurrentName - device electric current value name - usually cur_current or 18 (only if device supports)CurrentFactor - the number by which the CurrentName value is multiplied. You must enter the value so that the result should be in units of amperes (A). So if the device returns a value in milliamps (mA), enter 0.001. Example: device returns 2300 mA, 2300*0.001 = 2.3 APowerName - device electric power value name - usually cur_power or 19 (only if device supports)PowerFactor - the number by which the PowerName value is multiplied. You must enter the value so that the result should be in units of watts (W). So if the device returns a value in in hundreds of milliwatts, enter 0.1. Example: device returns value 15000 , 15000*0.1 = 1500 WVoltageName - device electric voltage value name - usually cur_voltage or 20 (only if device supports)VoltageFactor - the number by which the VoltageName value is multiplied. You must enter the value so that the result should be in units of volts (V). So if the device returns a value in in hundreds of millivolts, enter 0.1. Example: device returns value 2370 , 2370*0.1 = 237 VTemperatureName - device temperature value name - depends on device (example upper_temp or 3 - only if device supports)TemperatureFactor - the number by which the TemperatureName value is multiplied. You must enter the value so that the result should be in units of degrees Celsius (°C). So if the device returns a value in half degrees, enter 0.5. Example: device returns value 41 , 41*0.5 = 20.5 °CEnergyName - (only if device supports) - device total energy consumed (watt-hours) value name - currently don't know usual value name (you have to try to find it).EnergyFactor - the number by which the EnergyName value is multiplied. You must enter the value so that the result should be in units of watt-hours (Wh). So if the device returns a value in in hundreds of watt-hours, enter 0.1. Example: device returns value 5000, 5000*0.1 = 500 WhIntegration to SunnyHome
Click Add Device
ShellyPro3 for general deviceShellyPro4PM - for device which can measure Power valueShelly1PMPlus - for device which can measure Power value192.168.0.1:8801Testing device ON/OFF:
Assume that application is running on IP 192.168.0.1, port 8801.
0), enter to www browser:http://192.168.0.1:8801/rpc/Switch.GetStatus?id=0
http://192.168.0.1:8801/rpc/Switch.Set?id=0&on=true
http://192.168.0.1:8801/rpc/Switch.Set?id=0&on=false
Troubleshooting:
docker logs --tail 500 smarthomeconverter
(the most recent entries are at the top)
Content type
Image
Digest
sha256:1f7996dda…
Size
71.9 MB
Last updated
over 1 year ago
docker pull dododuke/smarthomeconverter:32bit