Page 2 of 2

Re: http/https poller

Posted: Saturday 15 September 2018 12:55
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"

Re: http/https poller

Posted: Friday 30 November 2018 20:32
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 164 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 95 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

Re: http/https poller

Posted: Friday 25 January 2019 15:08
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

Re: http/https poller

Posted: Saturday 02 February 2019 16:38
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 120 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.

Re: http/https poller

Posted: Sunday 03 February 2019 13:58
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

Re: http/https poller

Posted: Monday 25 February 2019 21:10
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 3886 times

Re: http/https poller

Posted: Wednesday 01 May 2019 9:12
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


Re: http/https poller

Posted: Wednesday 01 May 2019 14:28
by sincze
Suggestion: Have a look at Pass2php and have as many php as you want at your fingertips.
:)

Re: http/https poller

Posted: Friday 03 May 2019 6:00
by Minglarn
Thanks for the tip.. I'll do that.



Skickat från min SM-N950F via Tapatalk


Re: http/https poller

Posted: Thursday 05 September 2019 23:35
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

Re: http/https poller

Posted: Monday 09 September 2019 18:52
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