The TUYA controller controls the plethora of low cost, Chinese made IOT devices that you can buy nearly everywhere online. This includes outlets, Light switches, and bulbs. Any of these basic devices that can be controlled by the Tuya, Smart Life, or Jinvoo Smart smartphone apps can be controlled by this controller. All setup and configuration must be first done using the appropriate smartphone app but afterwards, you can perform actual control through PowerHome.
Be aware that the control is accomplished using the undocumented Tuya cloud API that was developed for Home Assistant. These devices are all cloud controlled so PowerHome speaks to the cloud service and then the cloud service talks to the device and performs the requested action. This means internet connectivity is required and the cloud provider can potentially track when and what you are controlling.
Most of these devices can be flashed with an alternative firmware (Tasmota is very popular) which will then allow for local control of the device using MQTT
PowerHome supports on/off devices including devices such as powerstrips with multiple individually controlled outlets, dimmer switchs, and bulbs including adjustable color and temperature.
On/Off devices can be defined as IOT Input or IOT Output in the Digital IO screen. The Unit can be any value (the default of 0 is fine). If the device is a single controlled device (such as a single outlet) then set the Point column to 0. If the device has multiple control points (such as a powerstrip), set the point to the socket you wish to control (1 for the 1st socket, 2 for the 2nd socket, etc). If you wish to control ALL control points as a single device, then set the point value to 0. Set the IP/ Address column to the base unique Tuya ID (see below).
Dimmers, Color bulbs, and Scenes are all configured in the Analog IO screen. You can also configure your On/Off devices in the Analog IO screen (instead of the Digital IO screen) if you'd like a little more flexibility. On/Off, Dimmers, and Bulbs are defined using either the IOT Input or IOT Output device types. The Unit column determines what is actually being controlled as follows: 0 is used for an On/Off device. 1 is used for a dimmer or bulb (On/Off/Level) device. 2 is used strictly for adjusting Color and Temperature for a bulb (if you have a color bulb, you'll typically define two devices, one for the status and level and one for the color/temperature). 3 is used for specifying a specific scene.
In addition to the above single scene option (IOT Output, Unit 3), you can declare Scenes using Input and Output device types and set the Unit to 4. The difference is that an IOT Output, Unit 3 scene describes a single scene ID with the only option for control is to "Activate" the scene. An Output, Unit 4 scene allows you to define a dropdown list of scenes using a Range ID that allows you to select from multiple scenes to be controlled using a single device. Basically, if you have 5 scenes, you can create 5 IOT Output, Unit 3 devices or create 1 Output, Unit 4 device (or any combination thereof).
For IOT Input / IOT Output and Units 0 thru 3, you will enter the base unique Tuya identifier in the ROM ID / IP / Topic / Channel column. For Input / Output Unit 4 scenes, the ROM ID / IP / Topic / Channel is not available and instead the unique Tuya identifier for the scenes are defined in a Range of values and then that Range ID is assigned to the Input / Output Unit 4 device.
For Input / Output Unit 4 scenes, set the Point column to a unique value to distinguish it from other Input / Output Unit 4 scenes for the same controller (internally the Point column is not used but it needs to have a unique value in order to be saved to the database). For IOT Input / Output (Units 0 thru 3), set the point to the specific control point for the device. If the device has a single control point, then set the Point to 0. If the device has multiple control points, set the Point to the specific number. Using a Point value of 0 will cause ALL control points in a multiple control device to be controlled together.
For binary controlled devices (On / Off) in the Analog IO screen (IOT Input / IOT Output Unit 0), On / Off control is done by setting the output to 1 for Off or 2 for On (actually any value <= 1 will be treated internally as a 1 for Off. Any other value > 1 will be treated as a 2 for On).
For unit 1 devices (on/off/level) in the Analog IO screen, the value to "set" the device is different than the rawvalue that is used to store the current status. Because a Tuya device has multiple possible options, this value can be difficult to understand and needs some explaining. The value used to "set" or control a unit 1 device is calculated as follows: If you are setting a level, take the level (in a range of 0 to 100), multiply by 64 and then add 2 (adding 2 signifies that the device is turned on. Most Tuya devices automatically turn on when the brightness is set to a level > 0. If the brightness is set to 0, then most Tuya devices will turn off. You can set the brightness alone without the appropriate on/off value but PowerHome may not show the proper on/off status until the device is polled for its status). If you are just turning a device on or off without wanting to change the level, the set value is 2 for on or 1 for off (using a set value of 0 will automatically be converted to a 1).
The rawvalue that is used to determine the status of a unit 1 device is a bit more complicated that the value used to "set" the status. Because a device (such as a bulb) may also have a color option, a white color temperature, and support separate brightness levels for color and white modes, all of these data values must be included in the single rawvalue value. Bit 1 set signifies that the status is off. Bit 2 set signifies that the status is on. Bit 4 set indicates that the device is in "white" mode. Bit 8 set indicates that the device is in "color" mode. Bit 16 set indicates that the device does NOT support a separate color brightness. Bit 32 set indicates that the device DOES support a separate color brightness. Starting at bit 64 and continuing to bit 131072 is the "white" mode level (as well as the "color" mode level if bit 16 is set and bit 32 is clear). Starting at bit 262144 and continuing to bit 536870912 is the separate "color" mode brightness level (bit 16 would be clear and bit 32 would be set). You can determine the on/off status of a device by using the ph_and( ) function like this: if(ph_and(rawvalue,2) > 0,"On","Off"). You can determine the current mode of a device (white or color) with this statement: if(ph_and(rawvalue,12)= 8,"Color","White"). The following formula is an example of how to return the current brightness level depending upon the current mode: if(ph_and(rawvalue,40) = 40,ph_and(rawvalue,1073479680) / 262144,ph_and(rawvalue,262080) / 64).
For unit 2 devices (color/temperature) in the Analog IO screen, you "set" the status as follows. Bit 1 determines if the value being "set" is a "color" or a "temperature". Set bit 1 for color values and clear bit 1 for temperature values. If you are setting a "color", calculate the desired RGB color (for example Red would be rgb(255,0,0) which is equal to 255) and multiply by 2 and then add 1 (bit 1). To set a unit 2 device to Red, 255 * 2 + 1 = 511. If you are setting a "temperature", valid temperature values are from 1000K (Kelvin) to 10,000K. Take the desired temperature in Kelvin and multiple by 2 (do not add a 1). For a temperature of 3500K, use a rawvalue of 7000. Unlike Unit 1 devices, the rawvalue used to determine the status is the same as the rawvalue that is used to "set" the status. If a bulb does not support the setting of white temperature, you can set the mode by setting the unit 2 device to value of 0. If you wish to just toggle between color and white modes using the last color and white settings, you can send a value of 1 to go to color mode and a value of 0 to go to white mode. The next time the device is polled, it will update the appropriate color/temperature setting. Whenever you toggle modes in a unit 2 device, the equivalent unit 1 device will also have its first 4 bits updated (either 6 for On/white or 10 for On/color) to reflect the current mode.
For unit 3 devices (single scene activation) in the Analog IO screen, you "activate" a scene by sending a rawvalue of 2 (same value you would use to turn "on" a device). Since a scene cant be "deactivated", there is no equivalent "off" value which would normally be a 1. Since a unit 3 device is an IOT Input/Output device type and the unique scene ID is contained in the ROM ID / IP / Topic / Channel column, there isnt much else needed concerning the setting of a unit 3 device.
For unit 4 devices (scene activation by choosing from a list) in the Analog IO screen, you MUST declare the scenes by first creating a range of values containing the scenes you intend to use. This allows you to associate a raw (numeric) value with a unique Tuya scene ID (alphnumeric). You "activate" a scene by setting the rawvalue to the particular to the rawvalue that was assigned to the scene in the range of values. When the controller goes to activate the scene, it looks up the "Alpha Value" in the range of values (you must enter the Tuya unique scene ID in the "Alpha Value (Optional column)" in the range of values screen) associated with the Raw value and then sends that unique scene ID to the Tuya API.
In order to perform the setup within PowerHome of Tuya devices and scenes, the unique Tuya ID associated with the device or scene is needed for entry into the appropriate screens. Once you've configured your devices and scenes using your chosen smartphone Tuya app (Tuya, Smart Life, Jinvoo Smart) and defined the Tuya Cloud controller in PowerHome, you can retrieve these values as well as additional internal information by running the following formula. The example assumes that the ID of your PowerHome Tuya controller is "TUYA": ph_ctlrcmd(5,"TUYA",9998,0,0,"","")