rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
2.94k stars 562 forks source link

kWh DP is not available #1521

Open Zodiac-69 opened 1 year ago

Zodiac-69 commented 1 year ago

I have 3x Tuya 30A switches. The following DP's are shown by tinytuya:

mapping": { "1": { "code": "switch_1", "type": "Boolean", "values": {} }, "7": { "code": "countdown_1", "type": "Integer", "values": { "unit": "s", "min": 0, "max": 86400, "scale": 0, "step": 1 } }, "14": { "code": "relay_status", "type": "Enum", "values": { "range": [ "power_off", "power_on", "last" ] } }, "20": { "code": "add_ele", "type": "Integer", "values": { "unit": "kwh", "min": 0, "max": 50000, "scale": 3, "step": 100 } }, "21": { "code": "cur_current", "type": "Integer", "values": { "unit": "A", "min": 0, "max": 30000, "scale": 3, "step": 100 } }, "22": { "code": "cur_voltage", "type": "Integer", "values": { "unit": "V", "min": 0, "max": 5000, "scale": 1, "step": 1 } }, "23": { "code": "cur_power", "type": "Integer", "values": { "unit": "W", "min": 0, "max": 50000, "scale": 1, "step": 1 } } } Only DP 20 is not available in localtuya. On the Tuya Smart app, all the points are also shown. I installed them to monitor my Geyser (Hot Water) power consumption, we use 230Vac here in South Africa.

Some of my Tuya "Smart Sockets" have the same issue, DP 20 is not shown in LT, but they are shown in the app.

Even if i try to setup DP 20 manually, it is not available to setup. How can i resolve this?

LineF commented 1 year ago

With my plugs is the same problem (having add_ele on DP 17). This DP is missing as long as the measured value is zero. After having some power used, the DP is shown in tinytuya and it can be configured in the integration. (But there I still have first to remove the device completely and then re-deploy). I don't know if this missing DP (when value is zero) is by design or a bug.

Zodiac-69 commented 1 year ago

Hi LineF

I shall remove / add one of the devices when i get home tonight and see if this resolve the issue. I am presuming not as the device has been running for months, so the kWh value was not zero when i tried to add DP 20.

BobWs commented 1 year ago

I'm having the same problem! I followed the suggestion from @LineF and I indeed saw the DP17 after the device was powered but the kWh measure does not show, it sticks to 0,0 kWh. Screen_Shot

Could you share some more info how you got it working? Maybe you could also add some screenshots.

LineF commented 12 months ago

I found this discussion here which might be a pretty good description of the add_ele (add electricity) DP: https://github.com/rospogrigio/localtuya/issues/1444 There might be a bug because zero values are not transmitted.

Im receiving values but not as initially expected by me (total electricity summed up). image

Instead it seems to be the electricity summed up over the last half hour: reported add_ele (=energy) values (ignore graph before 10pm): image

reported power (wattage) of the device: image

I think it is difficult to use that add_ele value. When will you sum it up? Every half hour?

@BobWs: I had no problems getting values from my DP17 once it was defined initially.

BobWs commented 12 months ago

Okay thanks for the info. When I added DP17 even after a restart and waited for over an hour it was still empty just 0,0 kWh. I will read through the reference and see if I can find something useful for me to work with.

BobWs commented 12 months ago

Tried it again and still nothing! I don't understand why it isn't working for me. These are my entries (see screenshots): Maybe you could spot what I'm doing wrong...

18 - current mA 
19 - power W  (scale 0.1)
20 - voltage V  (scale 0.1)
17 - Usage kWh (scale 0)

Screen_Shot 1 Screen_Shot 2 Screen_Shot 3 Screen_Shot 4 Screen_Shot

Also How do I add the readings to the energy dashboard? If I get it to work eventually..

LineF commented 12 months ago

For DP 1 (on/off switch) I didn't configure the three additional entities (current, curr.consumption, voltage). I got into problems when I filled them in... Instead I have separate sensor entities (as you did eg. with DP 20). DP 17 I don't use for my energy panel - it doesn't make sense with it's half hour values. Instead I use the power sensor of the plug and convert it with the riemann integration to an energy value:

homeassistant:
  customize:
    sensor.paul_lueftung_kwh:
      device_class: "energy"
      state_class: "total_increasing"

sensor:
  - platform: integration
    source: sensor.paul_lueftung_power
    name: "Paul Lueftung kWh"
    unique_id: "paul_lueftung_kwh"
    unit_prefix: k
    unit_time: h
    round: 3
    method: left

This sensor then can be used as energy source in the enrgy panel.

BobWs commented 12 months ago

Okay I see, if it isn't to much trouble could you please write a small step-by-step for me how to do that with the "e riemann integration". I'm not that familiar with HA the only thing I manage so far is to get it to read my smart(grid)meter... TIA

BobWs commented 12 months ago

I think I have somehow manage to get the Energy Usage to work with the riemann integration. Now I see the kWh value and it is changes every time so I guess that is working! Screen_Shot 1 Screen_Shot

But it still doesn't show in the Energy Dashboard. How do I let it show in the Energy dashboard? Do I need to change or add something somewhere? TIA

BobWs commented 12 months ago

I have search through the HA Forum and as I understand I have to change the state_class to measurement or total_increasing as in your example. But I don't know where the yml file is to change that. Can you point me into the right direction?

LineF commented 12 months ago

As in my example above use the "homeassistant:" section (insert if not already present). With "customize" you can change the properties of your sensors. In my case I change/add the device_class and state_class of my sensor paul_lueftung_kwh which is generated by the riemann integration. This should give you the sensor in the energy dashboard.

BobWs commented 12 months ago

As in my example above use the "homeassistant:" section (insert if not already present). With "customize" you can change the properties of your sensors. In my case I change/add the device_class and state_class of my sensor paul_lueftung_kwh which is generated by the riemann integration.

I'm sorry to ask again but how do I make these changes? Where can I find to make these changes. Sorry for asking so much!

LineF commented 12 months ago

You add this in your configuration.yaml. You should get familiar with editing this file and what the risks are with this (erroneous file could inhibit restarting homeassistant, but there are checks you can make to avoud this). I use the Studio Code Server to edit my files on the system.

BobWs commented 12 months ago

You add this in your configuration.yaml.

Okay so I did it the right way, I added the sensors to the configuration.yaml file and restarted HA, but still nothing in the energy dashboard. This is what I added:


# Sensors
homeassistant:
  customize:
    sensor.tv_energy_usage:
      device_class: "energy"
      state_class: "total_increasing"
    sensor.wk_lamp_energy_usage:
      device_class: "energy"
      state_class: "total_increasing"
    sensor.fridge_energy_usage:
      device_class: "energy"
      state_class: "total_increasing"

sensor:
  - platform: integration
    source: sensor.tv_power
    name: "TV Energy Usage"
    unique_id: "TV Energy Usage"
    unit_prefix: k
    unit_time: h
    round: 3
    method: left

  - platform: integration
    source: sensor.wk_lamp_power
    name: "WK Lamp Energy Usage"
    unique_id: "WK Lamp Energy Usage"
    unit_prefix: k
    unit_time: h
    round: 3
    method: left

  - platform: integration
    source: sensor.fridge_power
    name: "Fridge Energy Usage"
    unique_id: "Fridge Energy Usage"
    unit_prefix: k
    unit_time: h
    round: 3
    method: left
LineF commented 12 months ago

hmm, looks fine. I don't see any errors. sorry, no more ideas...

BobWs commented 12 months ago

So after lot of searching the HA Community Forum I figured it out why it did show up in the Energy Dashboard. Very stupid of me not to realize that the Energy Configuration has moved into to "Dashboards" "Tab" under Settings! So once I found that again I could add the Devices and I got my graphics. Screen_Shot 2

The only thing I'm wondering is your also just a Sum of the energy use? Do you know if there is a way to get it per hour like the Grid Energy Usage (see below screenshot)? Screen_Shot 3 (Grid energy use per hour).

Also I removed the above sensor config from the configuration.yaml and it is still working. Adding the above to the configuration.yaml caused double sensors so I removed it to see if it was working and it did!

LineF commented 12 months ago

I think you have to generate an utility meter like here: https://community.home-assistant.io/t/sum-of-sensor-values-on-hourly-basis-for-solar-nbc-charges/403987

Second, I think you have to create your own energy dashboard because the standard board is not flexible enough. Somewhere I read about this...