Local-tuya

I have a couple of 3 phase tuya circuit breakers and the Tuya integration only shows four entities for each, power, child_lock, countdown (timer) and relay_status. So I decided to try out localtuya hoping more entities would be available. So when I added the device there are more DP’s available. And some of them I managed to recognize and was able to add them, like ‘total active power’, ’ total reverse power’, ‘leakage_current’ ‘breaker temperature’ and the power itself. For the countdown, I don’t fully know how I should add this, it is supposed to be a timer value “HH:MM”
and after that time it should toggle the breaker. But what kind of device type is that ? The other part is that some of the DP’s that show in the UI when adding entities have values I do not recognize. And in the Tuya app I see a lot more, like Current and power per phase. Some pictures that show how it looks like in the tuya app and what how the config looks like in the config_entries:





So how does the tuya app get these additional values and what should the solar_breaker_countdown actually be so that I could actually set a timer value?

Ok, I found that there are more options to get those hidden DP’s and one shows me this:


Two snapshots of values from the DP’s. So DP 101 has changing values, but encoded, but it starts with ‘CU’, the current?
And DP 102 as well, but it is interesting that it shows “ACxxACxxACxx” The voltage of the three phases? Same with 119 and 120, but these values did not change.

And apparently the CU can change to CR and AC to AB…
image
And if there is no power I get to see this:
image

And I figured out that 112 is the Over-Current threshold setting:
AIygAQE= > 36 A
AJCIAQE= > 37 A
AJRwAQE= > 38 A

Had the same problem with my Tuya two way meter, you will have to use something like a pyscript to decode this, I did check the each byte and compared it with reading in the tuya app. Here is my code:

@state_trigger('sensor.licznik_pradu_dol_fazaa')
def base64_decode_sensor_licznik():
    #!/usr/bin/env python3
    import base64
    import sys

    # Decoding value from datapoint 6 which is base64-based (manually activated)
    value_phase_a = state.get('sensor.licznik_pradu_dol_fazaa')
    value_decoded = base64.b64decode(value_phase_a)

    # Calculating Voltage from base64-decoded value
    value_voltage = round(int.from_bytes(value_decoded[13:15], byteorder='big')*0.1, 3)
    state.set('sensor.licznik_pradu_dol_voltage_py', value_voltage)

    # Calculating Current from base64-decoded value
    value_current = round(int.from_bytes(value_decoded[11:13], byteorder='big')*0.001, 3)
    state.set('sensor.licznik_pradu_dol_current_py', value_current)

    # Calculating Power from base64-decoded value
    value_power = round(int.from_bytes(value_decoded[2:4], byteorder='big')*0.001, 3) * (-1 if ord(value_decoded[0:1]) else 1)
    state.set('sensor.licznik_pradu_dol_power_py', value_power)
    
    # Calculating Reactive Power from base64-decoded value
    value_kvar = round(int.from_bytes(value_decoded[6:8], byteorder='big')*0.001, 3)
    state.set('sensor.licznik_pradu_dol_kvar_py', value_kvar)
    
    # Calculating Reactive PF from base64-decoded value
    value_pf = round(int.from_bytes(value_decoded[8:10], byteorder='big')*0.001, 3)
    state.set('sensor.licznik_pradu_dol_pf_py', value_pf)
    
    # Calculating Power direction from base64-decoded value
    value_dir = round(int.from_bytes(value_decoded[0:1], byteorder='big'))
    state.set('sensor.licznik_pradu_dol_dir_py', value_dir)

The problem is that I don’t know python…See if I can do something with this in a template. Thanks!

You don’t have to know python, install this custom component: https://github.com/custom-components/pyscript

Put the code I attached to new folder called pyscript and the file name base64_init.py

Now in the code you can find this:

@state_trigger('sensor.licznik_pradu_dol_fazaa')
def base64_decode_sensor_licznik():
    #!/usr/bin/env python3
    import base64
    import sys

    # Decoding value from datapoint 6 which is base64-based (manually activated)
    value_phase_a = state.get('sensor.licznik_pradu_dol_fazaa')
    value_decoded = base64.b64decode(value_phase_a)

Set sensors in the code you get from loca tuya DP you want to check. And then add your own sensor in with the value you want to find:

    # Calculating Voltage from base64-decoded value
    value_voltage = round(int.from_bytes(value_decoded[13:15], byteorder='big')*0.1, 3)
    state.set('sensor.licznik_pradu_dol_voltage_py', value_voltage)

state.set is the new sensor, the points you want to find are here [13:15] nd then at the end you can set the value by multiplying it by the factor of 0.1

After editing the base64 file you can reload the integration from developer tools, so you don’t have to restart HA.