Local Tuya and Hiking DDS238-2 wifi power meter

Hi, I just installed in my home the Hiking DDS238-2 wifi two-way power meter (actually it’s a clone made by OXT model T322S - I think it’s only available in Poland) and I got it working with local tuya, I can read the total power, import power and my export to the grid - which is great and that is what I bought it for :slight_smile:

But in my Tuya app I can see the values for current, current consumption and voltage - but I can’t get these values in local tuya (or the tuya cloud integration). I’ve tried using dp_id of 18, 19 and 20 like in a tuya smart plug but these do not work. Can anybody get me in the right direction with solving this?

This is the data from tuya iot device specification:

  "result": {
    "category": "dlq",
    "functions": [
      {
        "code": "switch_prepayment",
        "dp_id": 11,
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "energy_reset",
        "dp_id": 12,
        "type": "Enum",
        "values": "{\"range\":[\"empty\"]}"
      },
      {
        "code": "charge_energy",
        "dp_id": 14,
        "type": "Integer",
        "values": "{\"unit\":\"kW·h\",\"min\":0,\"max\":999999,\"scale\":0,\"step\":1}"
      },
      {
        "code": "switch",
        "dp_id": 16,
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "alarm_set_1",
        "dp_id": 17,
        "type": "Raw",
        "values": "{}"
      },
      {
        "code": "alarm_set_2",
        "dp_id": 18,
        "type": "Raw",
        "values": "{}"
      }
    ],
    "status": [
      {
        "code": "total_forward_energy",
        "dp_id": 1,
        "type": "Integer",
        "values": "{\"unit\":\"kW·h\",\"min\":0,\"max\":99999999,\"scale\":2,\"step\":1}"
      },
      {
        "code": "phase_a",
        "dp_id": 6,
        "type": "Raw",
        "values": "{}"
      },
      {
        "code": "phase_b",
        "dp_id": 7,
        "type": "Raw",
        "values": "{}"
      },
      {
        "code": "phase_c",
        "dp_id": 8,
        "type": "Raw",
        "values": "{}"
      },
      {
        "code": "fault",
        "dp_id": 9,
        "type": "Bitmap",
        "values": "{\"label\":[\"short_circuit_alarm\",\"surge_alarm\",\"overload_alarm\",\"leakagecurr_alarm\",\"temp_dif_fault\",\"fire_alarm\",\"high_power_alarm\",\"self_test_alarm\",\"ov_cr\",\"unbalance_alarm\",\"ov_vol\",\"undervoltage_alarm\",\"miss_phase_alarm\",\"outage_alarm\",\"magnetism_alarm\",\"credit_alarm\",\"no_balance_alarm\"]}"
      },
      {
        "code": "switch_prepayment",
        "dp_id": 11,
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "energy_reset",
        "dp_id": 12,
        "type": "Enum",
        "values": "{\"range\":[\"empty\"]}"
      },
      {
        "code": "balance_energy",
        "dp_id": 13,
        "type": "Integer",
        "values": "{\"unit\":\"kW·h\",\"min\":-999999999,\"max\":99999999,\"scale\":2,\"step\":1}"
      },
      {
        "code": "charge_energy",
        "dp_id": 14,
        "type": "Integer",
        "values": "{\"unit\":\"kW·h\",\"min\":0,\"max\":999999,\"scale\":0,\"step\":1}"
      },
      {
        "code": "leakage_current",
        "dp_id": 15,
        "type": "Integer",
        "values": "{\"unit\":\"mA\",\"min\":0,\"max\":1000000,\"scale\":1,\"step\":1}"
      },
      {
        "code": "switch",
        "dp_id": 16,
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "alarm_set_1",
        "dp_id": 17,
        "type": "Raw",
        "values": "{}"
      },
      {
        "code": "alarm_set_2",
        "dp_id": 18,
        "type": "Raw",
        "values": "{}"
      }
    ]
  },
  "success": true,
  "t": 1676070737064,
  "tid": "5c7e52b2a99811eda120e66c285aff6b"
}```
1 Like

It is probably because the device is not fully supported in via Local Tuya. I have the same issue with my Infrared heater. Shows up in Tuya, but when added to local Tuya it just shows as a generic device.

I’ve found a solution, on local tuya githu there is a great post by BartGysens https://github.com/rospogrigio/localtuya/issues/1193

Basically when adding the meter to local tuya you have to manually add dp_id 6 for one phase meter, and 6, 7 and 8 for three phase meters. Then maka a sensor with data from these sp_ids. Next you have to install pyscript form hacs and create a file in /pycsript folder called base64_int.py and copy this cofiguration (change the sensor names to what you want:

``@state_trigger(‘sensor.boiler_lavande_phase_a’)
def base64_decode_sensor_lavande():
#!/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.boiler_lavande_phase_a')
value_decoded = base64.b64decode(value_phase_a)

# Calculating Voltage from base64-decoded value
value_voltage = round(int.from_bytes(value_decoded[0:2], byteorder='big')*0.1, 1)
state.set('sensor.boiler_lavande_voltage_py', value_voltage)

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

# Calculating Power from base64-decoded value
value_power = round(int.from_bytes(value_decoded[6:8], byteorder='big')*0.001, 3)
state.set('sensor.boiler_lavande_power_py', value_power)``

Unfortunnetly the data bits form the above configuration did not work for me, so by trial and error I found all the bits I need, this is my cofigurtion:

``@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)``

It works great! The only one small problem I have is that for my power value bit [2:4] I get the correct value, but I do not get if it’s a positive or negative charge (I have a two-way meter), in the app it shows, but not in my cofiguration. thank’s to MaximumSU from github the problem with power value positive or negative charge is solved, i’ve updated my code above!