-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not fetching total energy from plug #18
Comments
Not an api limitation, is just what the device returns. I think the energy number is fetched from the cloud tuya service, but not a 100% sure. I have to look through tuyapi issues to confirm that. |
There was a previous tuya node (node-red-contrib-tuya-smart) that used to get the total daily power consumption from the tuya api . It currently does not work as it needs to be updated for the changes in 3.3 but since it was using tuyapi it should be possible ? Perhaps the only value in the cloud is the total overall power consumption ? |
if the device itself is returning a the dps index with overall daily energy it would come in the output. The device I used to develop this was one with power meter and I only got voltage, current and power. I perform the energy calculations in hass using integration sensor and utility meter. |
I think maybe in the old tuya firmware the device outputted the energy calculations in a dps index. I don’t have an old fw device to check that. |
Hum, perhaps it's omitted in the new firmware version then . Thanks ! |
I have to clarify that i don't use this node anymore since tuya convert managed to crack again the firmware OTA. Out of the three medion(ALDI) plugs i have, two of them i flash them with esphome, the third one still remains with tuya but not using it. So, i still have the old flow but disabled, so in one of my functions node i have this const dps = msg.payload.dps;
let state = null;
let power = null;
let voltage = null;
let current = null;
if ("1" in dps) {
state = (dps['1']) ? "ON" : "OFF";
}
msg.payload = {
state: state,
attributes: {power: "0 W",current:"0 mA",voltage:"0 V"}
};
if ("18" in dps) {
msg.payload.attributes.current = (dps['18']).toString() + " mA";
if (dps['18'] > 0) {
msg.payload.state = "ON"
}
}
if ("19" in dps) {
msg.payload.attributes.power = (dps['19']/10).toString() + " W";
if (dps['19'] > 0) {
msg.payload.state = "ON"
}
}
if ("20" in dps) {
msg.payload.attributes.voltage = (dps['20'] /10).toString() + " V";
}
if (msg.payload.state === null) {
delete msg.payload.state;
}
msg.topic = "tuya/" + msg.data.name + "/status"
return msg; So voltage and power divided by 10, and current stays in mA, guess if you want amps then divided by 1000 |
Thanks buddy, that was really helpful of you, appreciated ! :) Best of luck for the long journey down the road of automation ! |
Sorry , just 1 more question ! The way you have the function node setup sends only the status to HA, but wouldn't you need the sensors to be separated (sensor.voltage, sensor.watts, sensor.current) for HA and other integrations like utility meter ? I added this topic to my HA :
This ofcourse gets me the status of all parameters properly : {"current": "0 mA", "power": "0 W", "voltage": "235.9 V"} How are you getting the sensors for each of these ? Adding a template sensor for each seems overly long and complicated considering I have around 12 plugs . Thanks again! |
Yes I was sending the power as attribute then extracting the sensor as template. But yes I guess is more efficient to send it to a single topic or input text and create a sensor from there. |
Also the nodered hass plugin developer has just released a custom component to integrate these things easier into home assistant |
Hehe I actually came across that a few hours ago :) Just haven't figured how to merge all the plugs in a single flow (like in your example using mqtt) using the 3 sensor templates (power, voltage, current), my node red knowledge is very basic . ALready saved me tons of work though since I would need to add dozens of sensor templates otherwise . |
I think the problem is in the node I don’t send the node name. So I kept an array of objects where I had names associated with the keys and ids. Then matching the node returned id with a name. |
It's been working brilliantly so far, had no other options for my teckin SP22 plugs as they are not flashable even with tuya local 2.0(realtek chip) , this saved my life ! :D Just one last question, any way to add a switch which I can turn on and off ? I have 2 switches which I am unable to integrate directly using HA so I need to control these from Node Red . |
What do you mean to have a toggle button for the switch in nodered? If that’s the case you can use the node red dashboard. |
No, I meant switching the power on and off on the switch . I ended up using the set false and set true dps nodes together with a switch entity and it's working great ! The only thing left is reading the current state of my plug so I can update my input_boolean to on or off accordingly in case instead of my HA switch I manually power off / on my plug . How can I get a reading from the plug current state ? Thanks |
If you send a payload with string request it should return the current state. Also any changes when the physical button is pressed should come out from the node. |
Thanks got it working now, msg.payload.dps.1 was what I was looking for . Apparently there can only be 1 tcp connection at a time to the tuya api so the tuya HA integration wasn't really working out for me , as I already had the TCP connection open in Node Red for the power / voltage / current readings. Created some switches using input_booleans and now I can get them to show the power status of my plugs either by using the switch or toggling the power button directly on the plugs . This is hands down the best working solution if one is stuck with tuya original firmware as me, since my SP22 Tecking plugs have realtek chip instead of ESP and can't be flashed in any way ! |
I have similar issue and I have to integrate 11 sockets. TriptonPt could you please explain more in detail what you did or share the whole NR code and configuration.yaml part. I have even problem creating switch... |
configure all sockets in node red break down your problem in smaller parts and build from there |
@polyphia , can you show me your function-nodes? |
Hi, thanks for this component it works flawlessly for fetching my plugs instant readings .
This is probably not a real issue (api limitation ?) but I noticed it's getting all the values in the app except total KW.h (accumulated energy consumption) .
18 is current (it lacks the .), 19 is Power(W) (also lacks a . before last digit) and 20 is Voltage (also lacks a . before last digit) . All these seem to get fetched correctly (except for the lack of the decimal separator) except for the last variable in the tuya app (total KW.h) .
Any chance for this to get updated or is it an API limitation ?
Thanks
The text was updated successfully, but these errors were encountered: