sanlike0911 / node-red-contrib-tplink-tapo-connect-api

Apache License 2.0
48 stars 20 forks source link

Support for P110 plug already works #14

Open johnkazer opened 2 years ago

johnkazer commented 2 years ago

Hi - I have a P110 plug and it seems the existing config just works already. I've used the 'status' node so far and the data returned is all correct. I'll investigate what other API calls can be used - it'd be great to have access to the electricity use data.

sanlike0911 commented 2 years ago

Hi. Thank you for using this node-red-contrib-tplink-tapo-connect-api. Also, thank you for giving me your cooperation in the API test for P110.

sanlike0911

joside commented 2 years ago

I can confirm, I tested the status and toggle, both are working with P110 plugs. But the status response should have that power data included. Is there a way to get that data?

Steve928 commented 2 years ago

Hi This thread helped me decide to purchase a P110 to replace a SONOFF POW R2 - very difficult to get these (or the R3) in the UK at the moment - and then there's the cost. P110s are a fraction of the price and, as long as it's just basic functionality that's required, are fine for many applications.

To return the help, you ask how you get the Power (or any other information for that matter) from the msg.object.

Create an inject node and direct to the 'status' node which you've set up with the required information i.e. Tapo account email and password and (I use) fixed device IP address.

The output of the status node (containing the whole msg.object) now needs to be passed to a Function node to both extract and format the specific information required - e.g. Power in Watts or mW, and to how many decimal places etc.

My P110 reports the current load in mW - I guess the same for everyone! For my use I need Watts, so I have to divide by 1000 and turn the result into an integer.

My function note is therefore:

var value = msg.payload.tapoEnergyUsage.current_power;

msg.payload = Math.round(value / 1000);

return msg;

If you need to get other information that's available from the P110, then simply click on 'Object' in the Debug window and open up all the levels until you get to the data you want - in this case, the very final item: 'current_power'.

Hover over the name to reveal the three buttons on the right, and select the first one '>_' (Copy path). This will automatically copy the correct hierarchical path/name to the clipboard, which can then be pasted directly into the function Node e.g. "payload.tapoEnergyUsage.current_power".

Sorry if you already know bits and pieces of the above, but a few people reading this post will be new to some of this and I thought worth including.

sanlike0911 commented 2 years ago

Hi Thank you for using node-red-contrib-tplink-tapo-connect-api.

Thank you for your valuable advice. I couldn't debug because "P110" is not sold in my country. Your help will help in development.

If you like, Would you please send me the output of your "Status Node on P110" with the security information removed?

Steve928 commented 2 years ago

Hi As requested and anonymised:

tapoDeviceInfo: object device_id: "xxxxxxxxxxxD9634D2CD644FE88649671F9F8C64" fw_ver: "1.0.7 Build 210629 Rel.174901" hw_ver: "1.0" type: "SMART.TAPOPLUG" model: "P110" mac: "xx-xx-xx-xx-xx-xx" hw_id: "xxxxxxxxx1D61D400A11C4A3D41C51DA" fw_id: "00000000000000000000000000000000" oem_id: "xxxxxxxx7168B34151ABBCF86C88DF34" overheated: false ip: "192.168.xx.xx" time_diff: 0 ssid: "xxxxxxx" rssi: -70 signal_level: 1 latitude: nnnnnn longitude: -nn676 lang: "en_US" avatar: "" region: "Europe/London" specs: "" nickname: "" has_set_location_info: true device_on: true on_time: 223508 default_states: object type: "last_states" state: object tapoEnergyUsage: object today_runtime: 556 month_runtime: 6756 today_energy: 750 month_energy: 8871 local_time: "2022-06-13 09:16:09" past24h: array[24] past30d: array[30] past1y: array[12] past7d: array[7] current_power: 72242

sanlike0911 commented 2 years ago

I'm sorry to take up your time. Thank you.

KnappD commented 2 years ago

can i get some example flow to read data of P110?

Steve928 commented 2 years ago

I thought that my post on 11 June explains it and gives the code: Inject Node -> TP-Link TAPO node (to get the full message from the device) -> a function node to extract the required data from the full message.

As I wanted 'power' being used, my function node contained the following code (as per that previous post):

var value = msg.payload.tapoEnergyUsage.current_power; msg.payload = Math.round(value / 1000); return msg;

The TP-Link TAPO node needs to contain your TAPO account email and password and the IP address of the TAPO device you want the information from.