Getting useful data off Tuya-based power meter

I’m in need of some hacker, or a Home Automation Exorcist (aka @wendell ) I’m way over my head for this one. I gathered a bunch of info that might be useful but I don’t know what to do with it. Any experienced guiding would be highly appreciated. I already got the GPT runaround that makes you go in circles with potentially harmful consequences. I’d rather hear from a fleshbag that knows his stuff than a sicophantic chatbot.

The story

I’ve had several appliances die to brownouts so a few years ago I installed a simple power meter on my electrical panel. If I notice something’s funky, I can cut power to the whole house and monitor it until I see an appropiate voltage again. Of course this was never ideal, since I had to manually rush to the breaker to cut power.

This morning my old mains voltage readout died, kept resetting. Since now I’m full into home automation, I decided to get a “smart” power meter. I went to my local electrician store, asked around and got This (docs are in spanish sadly).

TL;DR, it’s a pretty nifty DIN-Rail device that not only gives voltage reading, it also gives a bunch of extra stats (power usage, power factor, frequency, etc).

So before calling in the electrician for the installation, I decided to wire it to a normal plug so I could go through the proccess of pairing and integrating it with my HomeAssistant.

The Struggle

The problem is, It only works fully on a god awful SmartLife app. I installed the official Tuya integration on HAOS and realised all the stats were “0” and could only controll the main breaker switch. I Jumped through several hoops, setting up a Tuya Developer Platform account so I could use LocalTuya (which was way more interesting being local-first)

After all that, I go to the setup page and I get one step closer to frustration, this is not reading anything! (while the stupid app was reporting everything correctly)

So here’s the thing: after looking through the debug section of the Tuya Dev portal, I noticed that the voltage readout (and most of other stats) were in a funky format (e.g. AAAAAAAAAAAD6AAAAAi+). I gave in and decided to use the word calculator (chatGPT) to see if it could make anything of it, and lo and behold it gave a proper answer.

Apparently, this random gibberish 15 byte string represents:

Hex: 00 00 00 00 00 00 00 00 03 e8 00 00 00 08 be
Int: [0, 0, 0, 0, 0, 0, 0, 0, 3, 232, 0, 0, 0, 8, 190]

where 03 e8 (hex) becomes = 1000 (decimal) and the last part 08 be becomes 2238, which lo and behold gives me what was at the time 223,8v (my handheld multimeter read 223v so it’s probably right).

The Hope

Long story short, I got the debug info off the LocalTuya integration, and I can definetly see the missing data there, it’s just it’s not in a format I can readily use. Apparently the LocalTuya integration expects numbered “DP” entities, whereas this thing is reporting them as named “DP” entities

Here’s a partial dump of LocalTuya’s debug json. Partial because I left some stuff that seem probably would dox myself :smile:


        "model": "Smart meter IVAP",
        "device_id": "XXXXXXXXXXXXXXXXX",
        "dps_strings": [
          "1 (value: 0)",
          "9 (value: 0)",
          "11 (value: False)",
          "12 (value: False)",
          "13 (value: 0)",
          "14 (value: 0)",
          "16 (value: True)",
          "101 (value: 0)",
          "102 (value: 0)",
          "103 (value: 0)",
          "105 (value: 5000)",
          "107 (value: 0)",
          "108 (value: 000000000000)",
          "109 (value: 0)",
          "110 (value: 0)",
          "111 (value: 1000)"
        ],
        "product_key": "i55reuttymjocx0j"
      }
    },
    "no_cloud": false,
    "region": "us",
    "updated_at": "1756161417995",
    "user_id": "az1...VQM",
    "username": "hass-int",
    "cloud_devices": {
      "eb94b20ca78e84d603rq4m": {
        "active_time": 1756141838,
        "biz_type": 18,
        "category": "dlq",
        "create_time": 1756141838,
        "icon": "smart/icon/ay1560212249260P1Twc/88226ba9911edd0677efe1727ef66adc.jpg",
        "id": "eb94b20ca78e84d603rq4m",
        "ip": "186.13.152.251",
        "lat": "0",
        "local_key": ")<L...W{M",
        "lon": "0",
        "model": "IVAP",
        "name": "Smart meter IVAP",
        "online": true,
        "owner_id": "262114164",
        "product_id": "i55reuttymjocx0j",
        "product_name": "Smart meter IVAP",
        "status": [
          {
            "code": "total_forward_energy",
            "value": 0
          },
          {
            "code": "phase_a",
            "value": "AAAAAAAAAAAD6AAAAAjh"
          },
          {
            "code": "phase_b",
            "value": ""
          },
          {
            "code": "phase_c",
            "value": ""
          },
          {
            "code": "fault",
            "value": 0
          },
          {
            "code": "switch_prepayment",
            "value": false
          },
          {
            "code": "clear_energy",
            "value": false
          },
          {
            "code": "balance_energy",
            "value": 0
          },
          {
            "code": "charge_energy",
            "value": 0
          },
          {
            "code": "leakage_current",
            "value": 0
          },
          {
            "code": "switch",
            "value": true
          },
          {
            "code": "alarm_set_1",
            "value": "AAAAAAAAAAAAAABkAAEOAACqAAAAAAAKAAAAAAAA"
          },
          {
            "code": "alarm_set_2",
            "value": "AAUAZAAFAB4APAAAAAAAAAA="
          },
          {
            "code": "total_energy",
            "value": 0
          },
          {
            "code": "backward_energy",
            "value": 0
          },
          {
            "code": "total_power",
            "value": 0
          },
          {
            "code": "temp",
            "value": -65500
          },
          {
            "code": "frequency",
            "value": 5001
          },
          {
            "code": "times",
            "value": 1
          },
          {
            "code": "countdown",
            "value": 0
          },
          {
            "code": "breaker",
            "value": "000000000000"
          },
          {
            "code": "reactive_energy",
            "value": 0
          },
          {
            "code": "reactive_power",
            "value": 0
          },
          {
            "code": "factor",
            "value": 1000
          }
        ],
        "sub": false,
        "time_zone": "-03:00",

And here is probably something that could be useful to figure it out, as it comes out curl’d from the Tuya dev API


{
  "result": [
    {
      "code": "total_forward_energy",
      "value": 0
    },
    {
      "code": "phase_a",
      "value": "AAAAAAAAAAAD6AAAAAjf"
    },
    {
      "code": "phase_b",
      "value": ""
    },
    {
      "code": "phase_c",
      "value": ""
    },
    {
      "code": "fault",
      "value": 0
    },
    {
      "code": "switch_prepayment",
      "value": false
    },
    {
      "code": "clear_energy",
      "value": false
    },
    {
      "code": "balance_energy",
      "value": 0
    },
    {
      "code": "charge_energy",
      "value": 0
    },
    {
      "code": "leakage_current",
      "value": 0
    },
    {
      "code": "switch",
      "value": false
    },
    {
      "code": "alarm_set_1",
      "value": "AAAAAAAAAAAAAABkAAEOAACqAAAAAAAKAAAAAAAA"
    },
    {
      "code": "alarm_set_2",
      "value": "AAUAZAAFAB4APAAAAAAAAAA="
    },
    {
      "code": "total_energy",
      "value": 0
    },
    {
      "code": "backward_energy",
      "value": 0
    },
    {
      "code": "total_power",
      "value": 0
    },
    {
      "code": "temp",
      "value": -65500
    },
    {
      "code": "frequency",
      "value": 5000
    },
    {
      "code": "times",
      "value": 1
    },
    {
      "code": "countdown",
      "value": 0
    },
    {
      "code": "breaker",
      "value": "000000000000"
    },
    {
      "code": "reactive_energy",
      "value": 0
    },
    {
      "code": "reactive_power",
      "value": 0
    },
    {
      "code": "factor",
      "value": 1000
    }
  ],
  "success": true,
  "t": 1756156464107,
  "tid": "799adb4c81f811f0ad5f1a96caf0cb23"
}

UPDATE:

I just learned I can get the numbered ID’s in the most convoluted way, by using the developer tools in my browser to sniff at the network queries when I request a log for a specific entity.

One step ahead, two behind: I now know dp_6 is “phase_A” which is the wonky-formated “raw” voltage readout
I’ll keep digging, but still no idea how to implement it into localtuya/HASS

Question, can this not be flashed with Tasmota or ESPHome? Does this not have an MCU?

Otherwise, you probably need to use an mqtt server to ger the raw data to HASIO and then you can convert the values to readable values to display in lovelace.

1 Like

I didn’t want to modify it just yet, since I didn’t know if i’d have to return it.

Anyway, I forgot to post back for future reference. I ended up using all of the LLMs available to me to decode the weird strings (which ended changing again when I installed it completely).

I still don’t get the hype around “vibe coding”. I spent 2 days getting led by the nose by a (moron) robot. It was miserable, and the results might not be “good”, but here’s the working code for configuration.yaml (using LocalTuya integration).

# Template sensors for decoding Tuya smart circuit breaker data
sensor:
  - platform: template
    sensors:
      edenor_active_power:
        friendly_name: "Edenor Active Power"
        device_class: power
        unit_of_measurement: kW
        value_template: >
          {% set s = states('sensor.edenor_raw') %}
          {% if s and s != 'unavailable' and s != 'unknown' %}
            {% set raw = s | base64_decode('latin-1') %}
            {% set b = raw | map('ord') | list %}
            {% set active_power = b[2] * 256 + b[3] %}
            {{ (active_power / 1000) | round(3) }}
          {% else %}
            0
          {% endif %}

      edenor_reactive_power:
        friendly_name: "Edenor Reactive Power"
        device_class: power
        unit_of_measurement: kVar
        value_template: >
          {% set s = states('sensor.edenor_raw') %}
          {% if s and s != 'unavailable' and s != 'unknown' %}
            {% set raw = s | base64_decode('latin-1') %}
            {% set b = raw | map('ord') | list %}
            {% set reactive_power = b[4] * 16777216 + b[5] * 65536 + b[6] * 256 + b[7] %}
            {{ (reactive_power / 1000) | round(3) }}
          {% else %}
            0
          {% endif %}

      edenor_power_factor:
        friendly_name: "Edenor Power Factor"
        device_class: power_factor
        unit_of_measurement: ""
        value_template: >
          {% set s = states('sensor.edenor_raw') %}
          {% if s and s != 'unavailable' and s != 'unknown' %}
            {% set raw = s | base64_decode('latin-1') %}
            {% set b = raw | map('ord') | list %}
            {% set power_factor = (b[8] * 256 + b[9]) / 1000 %}
            {{ power_factor | round(3) }}
          {% else %}
            0
          {% endif %}

      edenor_current:
        friendly_name: "Edenor Current"
        device_class: current
        unit_of_measurement: A
        value_template: >
          {% set s = states('sensor.edenor_raw') %}
          {% if s and s != 'unavailable' and s != 'unknown' %}
            {% set raw = s | base64_decode('latin-1') %}
            {% set b = raw | map('ord') | list %}
            {% set current = (b[11] * 256 + b[12]) / 1000 %}
            {{ current | round(3) }}
          {% else %}
            0
          {% endif %}

      edenor_voltage:
        friendly_name: "Edenor Voltage"
        device_class: voltage
        unit_of_measurement: V
        value_template: >
          {% set s = states('sensor.edenor_raw') %}
          {% if s and s != 'unavailable' and s != 'unknown' %}
            {% set raw = s | base64_decode('latin-1') %}
            {% set b = raw | map('ord') | list %}
            {% set voltage = (b[13] * 256 + b[14]) / 10 %}
            {{ voltage | round(1) }}
          {% else %}
            0
          {% endif %}

  - platform: integration
    source: sensor.edenor_active_power
    name: Edenor Energy
    method: trapezoidal
    round: 3

During the LocalTuya setup, make sure to add the custom dp ID “6” (phase_a) and set it as an ‘enum’ type sensor. This will make decoding easier, since you’ll keep all the previous states and easily export it as .csv to feed an AI to figure it out for you.

Bonus, Here’s a smaller template for use within “HASS » Developer Tools » Template Editor”

{% set s = "AAAD/wAAAkwDWQAUxAjG " %} #change this to the current value of phase_a
{% set raw = s | base64_decode("latin-1") %}
{% set b = raw | map('ord') | list %}
{% set active_power = b[2] * 256 + b[3] %}
{% set reactive_power = b[4] * 16777216 + b[5] * 65536 + b[6] * 256 + b[7] %}
{% set power_factor = (b[8] * 256 + b[9]) / 1000 %}
{% set current = (b[11] * 256 + b[12]) / 1000 %}
{% set voltage = (b[13] * 256 + b[14]) / 10 %}
Active Power (kW): {{ active_power / 1000 }}
Reactive Power (kVar): {{ reactive_power / 1000 }}
Power Factor: {{ power_factor }}
Current (A): {{ current }}
Voltage (V): {{ voltage }}

1 Like

Nice, you were able to do what I was talking about without needing MQTT and modifying the firmware.

Hey only commenting because the spec sheet says this has a 63A maximum current and many north american homes have between 100A to 200A mains supply. And many north american heaters and ac units require between 30-50A breakers themselves, not counting if you have multiple big appliances running simultaneously. Point being from a safty perspective i hope you are not drawing more than the 63A max through this device, and are using multiple one per circuit.

OP and test cases seem to be on a 240v system so North American power draws aren’t really a concern here (and would be halved give or take in that scenario).

If you take a piece of wire or electrical circuit rated to handle 63A @240v, the manufacure is saying it has a resistance of Xohms. Due to ohms law requriring a constant state we can assume exceding a 63A current on this wire at 240V would result in a state change as the resistance is constant. That state change is HEAT in other words pulling 100-200A through a device meant to handle 63A @240 would resut in melting/burning/fire/badtimes.

So back to whole home main breakers, which are designed to handle generally between 100A-200A of current through the breaker @240v, you should not try to pull 100A of current through this device, regardless of it being 120v or 240v either way it will melt, do to resistance(electrical fire and burnt down home).

Really this is the whole point of breakers drawing more current through a wire than its rated to handle resultss in heat and fires, why the breaker trips if you exceed the number on it.

Not arguing electrical theory. Simply stating that North American draws don’t really enter into the discussion here. Should be really easy to stay within manufacturer’s spec on that breaker.

Thanks for being concerned, but it’s all within standard specs for home installations here in Argentina. I just checked out of curiosity,

Peak current was ~18A (probably coincidence big appliances like freezer, water pump and/or dishwashing running together)

Regarding the installation, it’s not the only nor the first device working as a circuit breaker.
Grid » 100A breaker » GFD breaker » “smart” breaker/meter » 2x 20A “general” breakers for different areas of the house (which in turn have breakers down the line on separate panels)

Here’s the entrance panel. I kinda cringe at the idea of sharing it, because the only wires following the color code are the ones I installed, and to replace the incoming mains wires I’d have to call a licensed electrician from the power company.

  • Mains come from the 2 green wires (because the electrician thought color code was a mere suggestion) to the bottom ports of the GFD.
  • I also added a “regular” readout meter before the GFD, so I can monitor the mains voltage with the whole house powered down (to avoid brown-out damages, mostly in the summer)
  • From the top of the GFD, splits a thinner neutral wire that goes into the smart breaker
    Live from GFD goes to the live input of the smart breaker and then to the 2 “general” zone breakers
2 Likes

well… I think I’ll start researching on flashing these devices, as @Mastic_Warrior suggested.

Today I checked up on my crap mail and got a reminder that my “trial” was over and I had to renew. Went to the renewal site and… well shit…

image

Mental note: never ever buying a “tuya” device ever again

This topic was automatically closed 273 days after the last reply. New replies are no longer allowed.