API script /http polling Powerfox Energy tracker

All kinds of 'OS' scripts

Moderator: leecollings

Mirkoser
Posts: 32
Joined: Tuesday 28 August 2018 15:36
Target OS: Linux
Domoticz version: 2021/1
Location: Germany
Contact:

Re: API script /http polling Powerfox Energy tracker

Post by Mirkoser »

Thank you, related to this topic I have another question.
I tried to create another http request for my Wallbox.
Im struggling with the item.json…. Because the answer of my Wallbox is full of numbers and I cannot write e.g item.json.8062d in the code.


Answer of the http request
{"8000d":3473211392,"8002":1,"8003":258,"8004":263,"8005":1084,"8006":256,"8007":0,"8008s":"W00-00EA","8016s":"cFos Power Brain","8040":3,"8041":2,"8042d":1000,"8044":0,"8045":230,"8046":230,"8047":230,"8050q":121890,"8054d":22608230,"8056":1,"8057":0,"8058q":121890,"8062d":0,"8064d":0,"8066d":0,"8068d":0,"8070":0,"8071":0,"8120d":24}
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: API script /http polling Powerfox Energy tracker

Post by waltervl »

should be something like
Somevalue = item.json['8026d']
or perhaps
Somevalue = item.json.['8026d']
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Mirkoser
Posts: 32
Joined: Tuesday 28 August 2018 15:36
Target OS: Linux
Domoticz version: 2021/1
Location: Germany
Contact:

Re: API script /http polling Powerfox Energy tracker

Post by Mirkoser »

Somevalue = item.json['8026d']

That was the solution. But now I get the response „Nil“ in the log for the JSON 8026d value 🙃
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: API script /http polling Powerfox Energy tracker

Post by waltervl »

Because there is no "8026d"? :)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Mirkoser
Posts: 32
Joined: Tuesday 28 August 2018 15:36
Target OS: Linux
Domoticz version: 2021/1
Location: Germany
Contact:

Re: API script /http polling Powerfox Energy tracker

Post by Mirkoser »

oh damn...too much computer in the last days...now its working

Thanks a lot for all. I will post the running scripts as well
Mirkoser
Posts: 32
Joined: Tuesday 28 August 2018 15:36
Target OS: Linux
Domoticz version: 2021/1
Location: Germany
Contact:

Re: API script /http polling Powerfox Energy tracker

Post by Mirkoser »

here my running powerfox plugin . Values are loaded into a virtual dummy P1 Meter


Code: Select all

return {
	on = {
		timer = {
			'every minute' -- just an example to trigger the request
		},
		httpResponses = { 'Powerfoxtrigger' } -- must match with the callback passed to the openURL command
		
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'Powerfox',
	},
	execute = function(domoticz, item)

		if (item.isTimer) then
			domoticz.openURL({
				url = 'https://XXXXXXXXXX:[email protected]/api/2.0/my/main/current', -- X =Login Powerfox Y= PW
				method = 'GET',
				callback = 'Powerfoxtrigger', -- see httpResponses above.
			})
	end

	if (item.isHTTPResponse) then

			if (item.ok) then
				if (item.isJSON) then
				    
				    
				    local USAGE1 = item.json.A_Plus
					local RETURN1 = item.json.A_Minus
				    
				  GetWatt = item.json.Watt
				    
                    if  item.json.Watt < 0 then
                      CONS = 0
                      PROD = math.abs(GetWatt)
                    
                      	domoticz.devices('Stromverbrauch').updateP1(item.json.A_Plus, '0', item.json.A_Minus, '0', '0', item.json.Watt)
                      	 domoticz.log('negative watts', domoticz.LOG_INFO)
                      	  domoticz.log(item.json.Watt, domoticz.LOG_INFO)
                      	   domoticz.log(item.json.A_Plus , domoticz.LOG_INFO)
					         domoticz.log(item.json.A_Minus, domoticz.LOG_INFO)
                else
                      CONS = GetWatt
                      PROD = 0
                    
                      domoticz.devices('Stromverbrauch').updateP1(item.json.A_Plus, '0', item.json.A_Minus, '0', item.json.Watt, '0')
                        domoticz.log('posetive watts', domoticz.LOG_INFO)
                          domoticz.log(item.json.Watt, domoticz.LOG_INFO)
                           domoticz.log(item.json.A_Plus , domoticz.LOG_INFO)
					        domoticz.log(item.json.A_Minus, domoticz.LOG_INFO)
                end


					 
					end
		
	
					end
	   
		
			

		end

	end
}
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: API script /http polling Powerfox Energy tracker

Post by waltervl »

Great, thanks for sharing the end result!
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Mirkoser
Posts: 32
Joined: Tuesday 28 August 2018 15:36
Target OS: Linux
Domoticz version: 2021/1
Location: Germany
Contact:

Re: API script /http polling Powerfox Energy tracker

Post by Mirkoser »

Hi I need again some assistance…I try to import some data with http get from my wallbox

The answer of the request is( see below)Now my question is how to import one specific value of this answer. I mean for example line with „ power" : 612, . But there are more lines with the name „power“


Code: Select all

 {
"params" : {
"title" : "cFos Power Brain",
"desc" : "Standard-Konfiguration",
"max_total_power" : 11000,
"power_reserve" : 0,
"overdraft" : 0,
"max_total_evse_power" : 0,
"consumed_evse_power" : 0,
"remaining_evse_power" : 10388,
"lb_enabled" : true,
"disable_policy" : 1,
"ocpp_srv_tls_mode" : "off",
"ocpp_srv_port" : 19520,
"ocpp_srv_use_ext_cert" : false,
"ocpp_srv_cert_fn" : "",
"ocpp_srv_private_key_fn" : "",
"ocpp_srv_cacert_fn" : 
[
],
"price_model" : 0,
"fixed_price" : 0.000000,
"tibber_home_id" : "",
"cycle_time" : 3000,
"max_evses" : 3,
"shareware_mode" : false,
"version" : "1.9.1101",
"time" : 1651093245,
"vsn" : 
{
"vendorid" : 52997,
"version" : 17368141,
"productid" : 1,
"serialno" : "W00-00EA"
},
"cpu" : 58,
"mem" : 62,
"ocpp_gateway_license_cnt" : 0,
"ocpp_gateway_licenses_used" : 0
},
"devices" : [
{
"dev_type" : "meter_powerfox_http_json",
"device_enabled" : 1,
"name" : "Stromverbrauch Gesamt",
"address" : "https://backend.Powerfox.Energy/API/2.0/my/main/current",
"id" : 1,
"dev_id" : "M3",
"number" : 2,
"desc" : "powerfox http",
"com_err" : false,
"com_err_secs" : 26851,
"com_errors" : 25,
"last_error" : "HTTP CLT:  failed to open TLS connection to backend.Powerfox.Energy:443",
"is_evse" : false,
"used_phases" : 0,
"is_mock" : false,
"is_va" : false,
"invert" : false,
"import" : 2744864,
"export" : 4406790,
"power" : 612,
"current_l1" : 887,
"current_l2" : 887,
"current_l3" : 887,
"voltage_l1" : 0,
"voltage_l2" : 0,
"voltage_l3" : 0,
"role" : 3,
"model" : "Powerfox,Powerfox,1.0,1.0,0"
},
{
"dev_type" : "meter_powerbrain",
"device_enabled" : 1,
"name" : "S0 Zähler 2",
"address" : "meter2",
"id" : 3,
"dev_id" : "M2",
"number" : 3,
"desc" : "cFos Power Brain, S0 Zähler 2",
"com_err" : false,
"com_err_secs" : 297427,
"com_errors" : 0,
"last_error" : "",
"is_evse" : false,
"used_phases" : 0,
"is_mock" : false,
"is_va" : false,
"invert" : false,
"import" : 401107,
"export" : 0,
"power" : 0,
"current_l1" : 0,
"current_l2" : 0,
"current_l3" : 0,
"voltage_l1" : 230,
"voltage_l2" : 230,
"voltage_l3" : 230,
"role" : 4,
"model" : "cFos Power Brain,1.0,1.9.1101,W00-00EA"
},
{
"dev_type" : "meter_powerbrain",
"device_enabled" : 1,
"name" : "Stromverbrauch Garage",
"address" : "meter1",
"id" : 2,
"dev_id" : "M1",
"number" : 1,
"desc" : "cFos Power Brain, S0 Zähler 1",
"com_err" : false,
"com_err_secs" : 300716,
"com_errors" : 0,
"last_error" : "",
"is_evse" : false,
"used_phases" : 0,
"is_mock" : false,
"is_va" : false,
"invert" : false,
"import" : 778749,
"export" : 0,
"power" : 46,
"current_l1" : 67,
"current_l2" : 67,
"current_l3" : 67,
"voltage_l1" : 230,
"voltage_l2" : 230,
"voltage_l3" : 230,
"role" : 0,
"model" : "cFos Power Brain,1.0,1.9.1101,W00-00EA"
},
{
"dev_type" : "evse_powerbrain",
"device_enabled" : 1,
"name" : "Wallbox",
"address" : "evse",
"id" : 1,
"dev_id" : "E1",
"number" : 1,
"desc" : "cFos Power Brain 11kW",
"com_err" : false,
"com_err_secs" : 300716,
"com_errors" : 0,
"last_error" : "",
"is_evse" : true,
"used_phases" : 7,
"is_mock" : false,
"label" : "",
"min_charging_cur" : 6000,
"max_power" : 11040,
"prio" : 3,
"charging_enabled" : false,
"cur_charging_power" : 0,
"last_set_charging_cur" : 6000,
"total_energy" : 8625219,
"phases" : 0,
"state" : 1,
"model" : "cFos Power Brain,1.0,1.9.1101,W00-00EA",
"paused" : false,
"pause_time" : 300,
"pause_min_time" : 300,
"ucnt" : 1,
"evse" : 
{
"dc_sensor_faults" : 0,
"dc_last_test_time" : "2022-04-26T15:55:30.946Z",
"dc_sensor_fault" : false,
"dc_sensor_glitches" : 3,
"cp_state" : "Standby",
"cp_fault" : false,
"pp_state" : "no cable",
"charging" : false,
"current" : 0,
"enabled" : false
}
}
],
"loadmgr_disabled" : false
}
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: API script /http polling Powerfox Energy tracker

Post by waltervl »

Not completely sure but "power" : 612 is part of device with "dev_id" : "M3".
So if this M3 device is always in the same location in the json (first device in the list) you could try something like item.json.devices[0].power
or could also be item.json.devices[1].power.

If this not works you have to loop through the results

Code: Select all

		
		local result_table = item.json.devices
		local tc = #result_table
					
		for i = 1, tc do
			if result_table[i].dev_id == "M3" then
                            PowerRead = result_table[i].power
                	end
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Mirkoser
Posts: 32
Joined: Tuesday 28 August 2018 15:36
Target OS: Linux
Domoticz version: 2021/1
Location: Germany
Contact:

Re: API script /http polling Powerfox Energy tracker

Post by Mirkoser »

Perfect, thanks I will try. Yes m3 device will be always at the same position.. I will report:)
Mirkoser
Posts: 32
Joined: Tuesday 28 August 2018 15:36
Target OS: Linux
Domoticz version: 2021/1
Location: Germany
Contact:

Re: API script /http polling Powerfox Energy tracker

Post by Mirkoser »

Seems not working,

tried to receive the title just for testing: domoticz.log(item.JSON.params.title , domoticz.LOG_INFO)
thats the error in the log file
2022-05-01 19:27:11.936 Error: EventSystem: in TEST: [string "return {..."]:10: attempt to index a nil value (global 'domoticz')

here the response in raw data from by wallbox

Code: Select all

{
"params" : {
"title" : "cFos Power Brain",
"desc" : "Standard-Konfiguration",
"max_total_power" : 11000,
"power_reserve" : 0,
"overdraft" : 0,
"max_total_evse_power" : 0,
"consumed_evse_power" : 0,
"remaining_evse_power" : 14140,
"lb_enabled" : true,
"disable_policy" : 1,
"ocpp_srv_tls_mode" : "off",
"ocpp_srv_port" : 19520,
"ocpp_srv_use_ext_cert" : false,
"ocpp_srv_cert_fn" : "",
"ocpp_srv_private_key_fn" : "",
"ocpp_srv_cacert_fn" : 
[
],
"price_model" : 0,
"fixed_price" : 0.000000,
"tibber_home_id" : "",
"cycle_time" : 3009,
"max_evses" : 3,
"shareware_mode" : false,
"version" : "1.9.1101",
"time" : 1651298858,
"vsn" : 
{
"vendorid" : 52997,
"version" : 17368141,
"productid" : 1,
"serialno" : "W00-00EA"
},
"cpu" : 24,
"mem" : 57,
"ocpp_gateway_license_cnt" : 0,
"ocpp_gateway_licenses_used" : 0
},
"devices" : [
{
"dev_type" : "meter_powerfox_http_json",
"device_enabled" : 1,
"name" : "Stromverbrauch Gesamt",
"address" : "https://backend.Powerfox.Energy/API/2.0/my/main/current",
"id" : 1,
"dev_id" : "M3",
"number" : 2,
"desc" : "powerfox http",
"com_err" : false,
"com_err_secs" : 17714,
"com_errors" : 31,
"last_error" : "HTTP CLT:  failed to open TLS connection to backend.Powerfox.Energy:443",
"is_evse" : false,
"used_phases" : 0,
"is_mock" : false,
"is_va" : false,
"invert" : false,
"import" : 2770970,
"export" : 4593968,
"power" : -3140,
"current_l1" : -4551,
"current_l2" : -4551,
"current_l3" : -4551,
"voltage_l1" : 0,
"voltage_l2" : 0,
"voltage_l3" : 0,
"role" : 3,
"model" : "Powerfox,Powerfox,1.0,1.0,0"
},
{
"dev_type" : "meter_powerbrain",
"device_enabled" : 1,
"name" : "S0 Zähler 2",
"address" : "meter2",
"id" : 3,
"dev_id" : "M2",
"number" : 3,
"desc" : "cFos Power Brain, S0 Zähler 2",
"com_err" : false,
"com_err_secs" : 503040,
"com_errors" : 0,
"last_error" : "",
"is_evse" : false,
"used_phases" : 0,
"is_mock" : false,
"is_va" : false,
"invert" : false,
"import" : 425261,
"export" : 0,
"power" : 0,
"current_l1" : 0,
"current_l2" : 0,
"current_l3" : 0,
"voltage_l1" : 230,
"voltage_l2" : 230,
"voltage_l3" : 230,
"role" : 4,
"model" : "cFos Power Brain,1.0,1.9.1101,W00-00EA"
},
{
"dev_type" : "meter_powerbrain",
"device_enabled" : 1,
"name" : "Stromverbrauch Garage",
"address" : "meter1",
"id" : 2,
"dev_id" : "M1",
"number" : 1,
"desc" : "cFos Power Brain, S0 Zähler 1",
"com_err" : false,
"com_err_secs" : 506329,
"com_errors" : 0,
"last_error" : "",
"is_evse" : false,
"used_phases" : 0,
"is_mock" : false,
"is_va" : false,
"invert" : false,
"import" : 810522,
"export" : 0,
"power" : 37,
"current_l1" : 54,
"current_l2" : 54,
"current_l3" : 54,
"voltage_l1" : 230,
"voltage_l2" : 230,
"voltage_l3" : 230,
"role" : 0,
"model" : "cFos Power Brain,1.0,1.9.1101,W00-00EA"
},
{
"dev_type" : "evse_powerbrain",
"device_enabled" : 1,
"name" : "Wallbox",
"address" : "evse",
"id" : 1,
"dev_id" : "E1",
"number" : 1,
"desc" : "cFos Power Brain 11kW",
"com_err" : false,
"com_err_secs" : 506329,
"com_errors" : 0,
"last_error" : "",
"is_evse" : true,
"used_phases" : 7,
"is_mock" : false,
"label" : "",
"min_charging_cur" : 6000,
"max_power" : 11040,
"prio" : 3,
"charging_enabled" : false,
"cur_charging_power" : 0,
"last_set_charging_cur" : 6000,
"total_energy" : 8703602,
"phases" : 0,
"state" : 1,
"model" : "cFos Power Brain,1.0,1.9.1101,W00-00EA",
"paused" : false,
"pause_time" : 300,
"pause_min_time" : 300,
"ucnt" : 1,
"evse" : 
{
"dc_sensor_faults" : 0,
"dc_last_test_time" : "2022-04-28T07:25:18.416Z",
"dc_sensor_fault" : false,
"dc_sensor_glitches" : 3,
"cp_state" : "Standby",
"cp_fault" : false,
"pp_state" : "no cable",
"charging" : false,
"current" : 0,
"enabled" : false
}
}
],
"loadmgr_disabled" : false
}
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: API script /http polling Powerfox Energy tracker

Post by waltervl »

It should work
but you are using capital letters for JSON. DZvents is case sensitive!

"item.JSON.params.title" should be "item.json.params.title"
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest