rospogrigio / localtuya

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

Cant get energy monitoring values #562

Closed Markobu98 closed 3 years ago

Markobu98 commented 3 years ago

The problem

I set up local tuya and it works and all. However I dicovered that my switches have the option to show power consumption. I checked the entities and I can see that the switches have the attributes current_consumption, voltage and current but there are no seperate entities for this. The I saw that you can create them using the sensor platform: template. I added the neccessary code but when I check my config it gives an error. What didi I do wrong?

Environment

Steps to reproduce

  1. I added the code
  2. Checked my config
  3. Got the error

Configuration configuration.yaml or config_flow

Additional information

This is the error message I get:

Invalid config for [sensor.template]: invalid slug switch.marko_lampe_voltage (try switch_marko_lampe_voltage) for dictionary value @ data['sensors']. Got OrderedDict([('switch.marko_lampe_voltage', OrderedDict([('value_template', '{{ states.switch.marko_lampe.attributes.voltage }}'), ('unit_of_measurement', 'V')])), ('switch.marko_lampe_current', OrderedDict([('value_template', '{{ states.switch.marko_lampe.attributes.current }}'), ('unit_of_measurement', 'mA')])), ('switch.marko_lampe_current_consumption', OrderedDict([('value_template', '{{ states.switch.marko_lampe.attributes.current_consumption }}'), ('unit_of_measurement', 'W')]))]). (See ?, line ?).

jeremysherriff commented 3 years ago

I have this working for both LocalTuya and Xiaomi integration smart plugs. If you haven't figured it all out yet, let me know and I can share some configs.

Markobu98 commented 3 years ago

@jeremysherriff thanks. I have got this working lately.

fily1212 commented 2 years ago

How did you resolved this? I have the same problem

jeremysherriff commented 2 years ago

How did you resolved this? I have the same problem

@fily1212 I'm happy to help. Please post your localtuya configuration here (either screenshots of the config screens for the devices, or the yaml, depending on how you add them to Home Assistant).

fily1212 commented 2 years ago

@jeremysherriff Hi, it works also for me! Thank you! I didn't figure out at the first time that I have to add "sensor" after "switch" in the GUI.

niaosuan commented 2 years ago

May I know the step if added from GUI?