caseyjhol / node-red-contrib-tplink

A collection of Node-RED nodes for TP-Link Smart Home devices
https://www.npmjs.com/package/node-red-contrib-tplink-iot
MIT License
16 stars 15 forks source link

Get energy info #55

Open MyCodeRocks opened 3 years ago

MyCodeRocks commented 3 years ago

A quick question, have a bunch of the H110 switches with the power logging on it. When I add the node I can see under the node it shows the state and energy consumption. I want to use the energy consumption value to store it into influxdb, how would I flow that out. If I simply connect a debug node to the switch and on the switch use Output Payload - getMeterInfo and on the debug node use msg.payload - I don't see any values in the debug. I have also enabled the debug option on the switch nodes itself and not seeing any info in the debug window.

What I am trying to achieve is to eventually read the energy info from the switch then flow it into a influxdb DB. Would appreciate the guidance

ahanselka commented 2 years ago

Heya @MyCodeRocks. I know this is a pretty old question, so you may not even need guidance anymore, but I came across this issue and am doing something similar and might be able to help. I don't know much about Influx as I'm using PostgreSQL, but can tell you a bit about what I'm doing to achieve similar.

There is supposedly a way to subscribe to meter updates using a payload of startMeterUpdateEvents, but I've not been able to get that to work. Instead, I use node-red-contrib-cron-plus to send a getMeterInfo request every so often (I do 5 seconds). I am using an HS300, and thus have one cron task per plug. This then flows through a delay node to rate limit it since I've had issues with the Kasa connection timing out when things happen too fast. I do a limit of 1 msg/500ms.

I take the output from the Kasa node and send it through a function node to prepare the Postgres query and then finally send that query onward to the postgresql node to execute.

The Kasa node itself won't output anything on its own (that I am aware of), thus to test this you should use an inject node with the payload of getMeterInfo to trigger a reading. If you have debug checked in the Kasa node itself, you will see a message indicating that it is processing the command and if you send that on to a debug node, you should see the payload, which will be an Object containing all the readings.

I hope this helps if you even still need it!

EDIT: I just noticed https://github.com/caseyjhol/node-red-contrib-tplink/issues/50, so I will look into replacing cron with startMeterEvents

sunnyysh commented 2 years ago

Hi @MyCodeRocks. Also a fellow newbie here. after looking at flow posted by other user I got it working using an inject note. try to import this [ { "id": "891b6d5308f462a8", "type": "tab", "label": "Flow 1", "disabled": false, "info": "", "env": [] }, { "id": "8ae1df89c44b5a1a", "type": "kasa", "z": "891b6d5308f462a8", "name": "HomeLab", "device": "192.168.40.176", "interval": 60000, "eventInterval": 15000, "payload": "getMeterInfo", "payloadType": "info", "debug": false, "x": 540, "y": 380, "wires": [ [ "6a0692f2bf434456", "eb6b2fc54a77c8b8" ] ], "info": "var newMsg = { payload:msg.payload.getMeterInfo }\nreturn newMsg;" }, { "id": "6a0692f2bf434456", "type": "debug", "z": "891b6d5308f462a8", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "statusVal": "", "statusType": "auto", "x": 950, "y": 280, "wires": [] }, { "id": "eb6b2fc54a77c8b8", "type": "influxdb out", "z": "891b6d5308f462a8", "influxdb": "5592296719d30a4c", "name": "Influx", "measurement": "power", "precision": "", "retentionPolicy": "", "database": "database", "precisionV18FluxV20": "ms", "retentionPolicyV18Flux": "", "org": "organisation", "bucket": "bucket", "x": 1170, "y": 360, "wires": [] }, { "id": "8ea4208e.d3679", "type": "inject", "z": "891b6d5308f462a8", "name": "", "props": [ { "p": "payload" } ], "repeat": "5", "crontab": "", "once": true, "onceDelay": 0.1, "topic": "", "payload": "getMeterInfo", "payloadType": "str", "x": 360, "y": 460, "wires": [ [ "8ae1df89c44b5a1a" ] ] }, { "id": "5592296719d30a4c", "type": "influxdb", "hostname": "http://localhost", "port": "8086", "protocol": "http", "database": "TPlink", "name": "TP_link", "usetls": true, "tls": "", "influxdbVersion": "1.x", "url": "http://localhost:8086", "rejectUnauthorized": true, "credentials": {} } ]