http/https poller

Moderator: leecollings

Jumper3126
Posts: 105
Joined: Thursday 31 December 2015 15:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: http/https poller

Post by Jumper3126 »

Got it running :D
Perhaps not the cleanest way, but it works and that is the main goal

Wrote a bash file, based on this onehttp://www.domoticz.com/forum/viewtopic ... ase#p56105.
I have 14 panels, you'll have to adjust the script for the amount of panels, the ip adress of your enphase gateway and the installer password of your system (see https://thecomputerperson.wordpress.com ... r-toolkit/).

Run the script every 5 minutes using crontab

Code: Select all

#!/bin/bash
# bash script to read production per panel from Enphase gateway
# V1.0 15/09/2018
# Based on script by Koen Vanduffel

# variables
enphase_IP="192.168.1.xx"

panel1_idx="989"
panel2_idx="1004"
panel3_idx="991"
panel4_idx="992"
panel5_idx="993"
panel6_idx="994"
panel7_idx="995"
panel8_idx="996"
panel9_idx="997"
panel10_idx="998"
panel11_idx="999"
panel12_idx="1001"
panel13_idx="1002"
panel14_idx="1003"

# Read Enphase status page
DATA=`wget --user installer --password xxxxxxxx -q -O - $enphase_IP/api/v1/production/inverters`

# Extract data per panel
PANEL1=`echo $DATA | awk '{print $136, $142, $144}'`
PANEL2=`echo $DATA | awk '{print $148, $154, $156}'`
PANEL3=`echo $DATA | awk '{print $88, $94, $96}'`
PANEL4=`echo $DATA | awk '{print $124, $130, $132}'`
PANEL5=`echo $DATA | awk '{print $52, $58, $60}'`
PANEL6=`echo $DATA | awk '{print $28, $34, $36}'`
PANEL7=`echo $DATA | awk '{print $16, $22, $24}'`
PANEL8=`echo $DATA | awk '{print $40, $46, $48}'`
PANEL9=`echo $DATA | awk '{print $4, $10, $12}'`
PANEL10=`echo $DATA | awk '{print $76, $82, $84}'`
PANEL11=`echo $DATA | awk '{print $112, $118, $120}'`
PANEL12=`echo $DATA | awk '{print $64, $70, $72}'`
PANEL13=`echo $DATA | awk '{print $160, $166, $168}'`
PANEL14=`echo $DATA | awk '{print $100, $106, $108}'`

echo $PANEL1
echo $PANEL2
echo $PANEL3
echo $PANEL4
echo $PANEL5
echo $PANEL6
echo $PANEL7
echo $PANEL8
echo $PANEL9
echo $PANEL10
echo $PANEL11
echo $PANEL12
echo $PANEL13
echo $PANEL14

# Extract production per panel
POWER1=`echo $PANEL1 | awk '{print $0}'`
POWER2=`echo $PANEL2 | awk '{print $0}'`
POWER3=`echo $PANEL3 | awk '{print $0}'`
POWER4=`echo $PANEL4 | awk '{print $0}'`
POWER5=`echo $PANEL5 | awk '{print $0}'`
POWER6=`echo $PANEL6 | awk '{print $0}'`
POWER7=`echo $PANEL7 | awk '{print $0}'`
POWER8=`echo $PANEL8 | awk '{print $0}'`
POWER9=`echo $PANEL9 | awk '{print $0}'`
POWER10=`echo $PANEL10 | awk '{print $0}'`
POWER11=`echo $PANEL11 | awk '{print $0}'`
POWER12=`echo $PANEL12 | awk '{print $0}'`
POWER13=`echo $PANEL13 | awk '{print $0}'`
POWER14=`echo $PANEL14 | awk '{print $0}'`

echo $POWER1
echo $POWER2
echo $POWER3
echo $POWER4
echo $POWER5
echo $POWER6
echo $POWER7
echo $POWER8
echo $POWER9
echo $POWER10
echo $POWER11
echo $POWER12
echo $POWER13
echo $POWER14

# Execute curl command to post to Domoticz
curl -i -H "Accept: application/json" "http://localhost:8080/json.htm?type=command&param=udevice&idx=$panel1_idx&nvalue=0&svalue=$POWER1;$W"
curl -i -H "Accept: application/json" "http://localhost:8080/json.htm?type=command&param=udevice&idx=$panel2_idx&nvalue=0&svalue=$POWER2;$W"
curl -i -H "Accept: application/json" "http://localhost:8080/json.htm?type=command&param=udevice&idx=$panel3_idx&nvalue=0&svalue=$POWER3;$W"
curl -i -H "Accept: application/json" "http://localhost:8080/json.htm?type=command&param=udevice&idx=$panel4_idx&nvalue=0&svalue=$POWER4;$W"
curl -i -H "Accept: application/json" "http://localhost:8080/json.htm?type=command&param=udevice&idx=$panel5_idx&nvalue=0&svalue=$POWER5;$W"
curl -i -H "Accept: application/json" "http://localhost:8080/json.htm?type=command&param=udevice&idx=$panel6_idx&nvalue=0&svalue=$POWER6;$W"
curl -i -H "Accept: application/json" "http://localhost:8080/json.htm?type=command&param=udevice&idx=$panel7_idx&nvalue=0&svalue=$POWER7;$W"
curl -i -H "Accept: application/json" "http://localhost:8080/json.htm?type=command&param=udevice&idx=$panel8_idx&nvalue=0&svalue=$POWER8;$W"
curl -i -H "Accept: application/json" "http://localhost:8080/json.htm?type=command&param=udevice&idx=$panel9_idx&nvalue=0&svalue=$POWER9;$W"
curl -i -H "Accept: application/json" "http://localhost:8080/json.htm?type=command&param=udevice&idx=$panel10_idx&nvalue=0&svalue=$POWER10;$W"
curl -i -H "Accept: application/json" "http://localhost:8080/json.htm?type=command&param=udevice&idx=$panel11_idx&nvalue=0&svalue=$POWER11;$W"
curl -i -H "Accept: application/json" "http://localhost:8080/json.htm?type=command&param=udevice&idx=$panel12idx&nvalue=0&svalue=$POWER12;$W"
curl -i -H "Accept: application/json" "http://localhost:8080/json.htm?type=command&param=udevice&idx=$panel13_idx&nvalue=0&svalue=$POWER13;$W"
curl -i -H "Accept: application/json" "http://localhost:8080/json.htm?type=command&param=udevice&idx=$panel14_idx&nvalue=0&svalue=$POWER14;$W"
berrevoets
Posts: 4
Joined: Monday 12 November 2018 12:40
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10240
Location: kapelle,netherlands
Contact:

Re: http/https poller

Post by berrevoets »

Hello Jumper,

i am trying to get your nice script to work on my domoticz but i run into some problems.
could you help me out on how to edit the script?
envoy.sh.txt
(4.17 KiB) Downloaded 155 times
i got some faults in the log about Illegal characters found in URL curl, al to do with the last lines , if i remove some lines i get less faults.
fault log.txt
(1.84 KiB) Downloaded 84 times
at this moment i see from 12 panels values in the log ( i have 13) but no readings in the virtual sensors.

i hope you can point me in the right direction , i am new to this scrips.

greetings marco
lightmanster
Posts: 4
Joined: Friday 12 January 2018 14:31
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: http/https poller

Post by lightmanster »

Hi Guys

I rewrote the previous script into a lua script. So everyone can use it in the events of domoticz. It is lua time based script.

Fill in your ipadress of the envoy device.
Fill in passwd for installer (see previous reply)
Fill in the serialnumber of the microconverters

the code as comments could be used as debug info.

Code: Select all

interval = 1
local m = os.date('%M')

if (m % interval == 0) then

json = (loadfile "/home/root/domoticz/scripts/lua/JSON.lua")()
local config=assert(io.popen('curl --anyauth --user installer:****** http://ipadress/api/v1/production/inverters')) -- json data off all micoroconverters
local Stringjson = config:read('*all')
config:close()
local jsonData = json:decode(Stringjson)

commandArray = {}


tc = #jsonData
for i = 1, tc do

	if ( jsonData[i].serialNumber == "serialnumberpanelx" ) then
        print("panel 1")
--	    print(jsonData[i].serialNumber) 
--	    print(jsonData[i].lastReportWatts)
        panel1=jsonData[i].lastReportWatts
       
		
	elseif (jsonData[i].serialNumber == "serialnumberpanelx" ) then
		print("panel 2")
--        print(jsonData[i].serialNumber) 
--	   print(jsonData[i].lastReportWatts)
       panel2=jsonData[i].lastReportWatts

-- repeat as many panels you have 	   
	   
	end 
end

  commandArray[#commandArray+1] = {['UpdateDevice'] = 'IDXdummypanel1|1|'..panel1}
  commandArray[#commandArray+1] = {['UpdateDevice'] = 'IDXdummypanel2|1|'..panel2}

end
return commandArray
berrevoets
Posts: 4
Joined: Monday 12 November 2018 12:40
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10240
Location: kapelle,netherlands
Contact:

Re: http/https poller

Post by berrevoets »

Hello lightmanster,

Great tht you spend time on this thing , i realy like to get it working.

but i run it to some problems withe the script

i get a message at line 6 (see pic)

6 json = (loadfile "/home/root/domoticz/scripts/lua/JSON.lua")() if i remove the last () then the next fault is move to line 10
10 local jsonData = json:decode(Stringjson) ( do not know how to troubleshoot further
Envoy2.txt
my lua script, without pw
(4.23 KiB) Downloaded 106 times

wat i did so far :
setup/harware ,create 1 dummy (idx10) and create 13 virtual sensors under it (idx 39-51) the custom type.
put lua script in events to let it run by domoticz (with serial numbers idx and pw)
also try to run it from home/pi/domoticz/scrips/lua

i hope you can help me out , i am new to working with these scripts , can not find out wat i am doing wrong.
Attachments
Schermopname (76) small.png
Schermopname (76) small.png (169.97 KiB) Viewed 3933 times
Schermopname (77) small.png
Schermopname (77) small.png (322.71 KiB) Viewed 3933 times
berrevoets
Posts: 4
Joined: Monday 12 November 2018 12:40
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10240
Location: kapelle,netherlands
Contact:

Re: http/https poller

Post by berrevoets »

just found one fault in my script, i wrote the serial numbers wrong in it without the first char.

still i get the same fault

2019-02-03 13:46:07.780 Error: EventSystem: in envoy 1paneel: [string "interval = 1..."]:6: attempt to call a nil value

i did login on the envoy, checked the serial numbers and the string my string lookslike:

]
{
"serialNumber": "121816023245",
"lastReportDate": 1549197357,
"lastReportWatts": 115,
"maxReportWatts": 164
},
{
next panel....


do i have to fill in a idx ? how wil it look like for one panel with the IDX =39 and the name is dummypanel1 ?

greetings marco
User avatar
Minglarn
Posts: 214
Joined: Friday 21 August 2015 19:27
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.8153
Location: Stockholm / Sweden
Contact:

Re: http/https poller

Post by Minglarn »

Is it possible to run a php script instead of a lua?

I really suck when it comes to lua. I do prefer PHP at all times. :)
At the command field I do want to run a PHP script running on my HTTP server...
1564.JPG
1564.JPG (35.21 KiB) Viewed 3777 times
When you eliminate the impossible, whatever remains, however improbable, must be the truth.” -Spock in Star Trek VI
User avatar
Minglarn
Posts: 214
Joined: Friday 21 August 2015 19:27
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.8153
Location: Stockholm / Sweden
Contact:

Re: http/https poller

Post by Minglarn »

Well I guess not.
Feel kind of stupid to call a lua script and then php script from inside lua.

Well well. This should be changed in further versions of Domoticz.

Skickat från min SM-N950F via Tapatalk

When you eliminate the impossible, whatever remains, however improbable, must be the truth.” -Spock in Star Trek VI
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: http/https poller

Post by sincze »

Suggestion: Have a look at Pass2php and have as many php as you want at your fingertips.
:)
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
Minglarn
Posts: 214
Joined: Friday 21 August 2015 19:27
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.8153
Location: Stockholm / Sweden
Contact:

Re: http/https poller

Post by Minglarn »

Thanks for the tip.. I'll do that.



Skickat från min SM-N950F via Tapatalk

When you eliminate the impossible, whatever remains, however improbable, must be the truth.” -Spock in Star Trek VI
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: http/https poller

Post by FireWizard »

Hi,

This thread suppose to be a discussion on how to use the http/https poller.
However it is more focussed on how to get the power production of each Enphase solar panel inverter in Domoticz. All kind of scripts are used, bash, lua, etc. In my opinion the best would be, that it is natively supported by Domoticz.
Therefore I made a request.
See: https://www.domoticz.com/forum/viewtopi ... 31&t=29170.

However I don't get any reaction from the developpers so far.

If it is only about, how to get the power production, max power and the inverter status in Domoticz, I can publish my Node Red flow(s) with some explanation.

Regards
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: http/https poller

Post by FireWizard »

Hi,

As said, the topic on how to extract the individual Power production of Enphase micro inverters with Node Red and MQTT has nothing to do with the http/https poller. Instead of continuing here I created a new thread, specific for this topic.

See: https://www.domoticz.com/forum/viewtopi ... 14&t=29331.

Regards
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest