Page 3 of 3
Re: Values are not sent to influxdb
Posted: Sunday 15 March 2020 23:47
by waaren
MeAlbert wrote: ↑Sunday 15 March 2020 20:58
But I see no values coming in the influx database. I have all settings correct. The logging is giving the folowing result.
Code: Select all
2020-03-15 17:24:05.694 Status: dzVents: Debug: Push to Influx: OpenURL: post data = nil
2020-03-15 17:24:05.695 Status: dzVents: Debug: Push to Influx: OpenURL: headers = nil
2020-03-15 17:24:05.695 Status: dzVents: Debug: Push to Influx: OpenURL: callback = nil
2020-03-15 17:24:05.697 Status: dzVents: Info: Push to Influx: ------ Finished Script #4
I assume the nil values are the problem. But how to fix???
These nil values are expected and not the problem here.
What is the device type and subtype for device 64
How did you configure the data push in domoticz for device 64 ?
What values do you want to send to InfluxDB ?
What do see in the logfile when you send data from another (non virtual) device to influxDB ?
Re: Values are not sent to influxdb
Posted: Monday 16 March 2020 10:01
by MeAlbert
The device is a general kWh type. The complete code for the device is:
Code: Select all
return {
on =
{
timer = { 'every minute' }
},
logging =
{
level = domoticz.LOG_DEBUG, -- for debugging
level = domoticz.LOG_INFO,
marker = "WP vermogen per uur"
},
data =
{
KwH = { initial = 0}
},
execute = function (domoticz, timer)
domoticz.log ('KwH = ' .. domoticz.data.KwH)
local WpPower = domoticz.devices(70).WhActual / 60
domoticz.log ('WpPower = ' .. WpPower)
domoticz.log ('Huidige vermogen in Wh (WhaActual) ' .. domoticz.devices(70).WhActual)
domoticz.data.KwH = domoticz.data.KwH + WpPower
domoticz.log (' Nieuwe kWh waarde ' .. domoticz.data.KwH)
domoticz.devices(64).updateElectricity ( domoticz.devices(70).WhActual , domoticz.data.KwH)
end
}
Sending the actual watts (WhActual )is just what I need.
Most of my devices are dummy devices. I have youless device, PVOutput, Weer(open weather map) and a MQTT client.
Code: Select all
2020-03-16 09:58:50.217 (YouLess) P1 Smart Meter (Totale huis verbruik.)
2020-03-16 09:58:50.263 (YouLess) General/kWh (WP verbruik)
2020-03-16 09:58:50.402 InfluxLink: value Delivery-2,idx=2,name=Totale-huis-verbruik. value=8344568
2020-03-16 09:58:50.403 InfluxLink: value Delivery-current,idx=2,name=Totale-huis-verbruik. value=1318.0
If you need more info please let me know. I can make screenshots if you want.
Re: Values are not sent to influxdb
Posted: Monday 16 March 2020 17:36
by MeAlbert
I see this error messages log file
2020-03-16 12:07:49.278 Error: Could not determine data push value
2020-03-16 12:07:49.289 Error: Could not determine data push value
2020-03-16 12:07:49.290 Error: Could not determine data push value
2020-03-16 12:08:03.314 Error: dzVents: local netWork not open for dzVents openURL call !
2020-03-16 12:08:03.315 Error: dzVents: check dzVents wiki (look for 'Using dzVents with Domoticz')
Re: Values are not sent to influxdb
Posted: Monday 16 March 2020 17:56
by waaren
MeAlbert wrote: ↑Monday 16 March 2020 17:36
2020-03-16 12:08:03.314 Error: dzVents: local netWork not open for dzVents openURL call !
2020-03-16 12:08:03.315 Error: dzVents: check dzVents wiki (look for 'Using dzVents with Domoticz')
Please read
This information on the wiki
Also send you a PM
Re: Values are not sent to influxdb
Posted: Monday 20 April 2020 12:50
by MeAlbert
The script is working fine but I see two things happening I would like to prevent from happening.
The first is that I have noticed that when a trigger comes to the script it always tries to push the value a second time which is then prevented by the scripts if statement. But I see the error message that is given then back in the logging.
Code: Select all
2020-04-20 12:04:03.564 Status: dzVents: Debug: Push to Influx: Device Vermogen Garage was changed 2223
2020-04-20 12:04:03.564 Status: dzVents: Debug: Push to Influx: OpenURL: url = http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=79&nvalue=0&svalue=2223
2020-04-20 12:04:03.565 Status: dzVents: Debug: Push to Influx: OpenURL: method = GET
2020-04-20 12:04:03.565 Status: dzVents: Debug: Push to Influx: OpenURL: post data = nil
2020-04-20 12:04:03.565 Status: dzVents: Debug: Push to Influx: OpenURL: headers = nil
2020-04-20 12:04:03.565 Status: dzVents: Debug: Push to Influx: OpenURL: callback = nil
2020-04-20 12:04:03.568 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
2020-04-20 12:04:03.595 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-04-20 12:04:04.240 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "KWH Garage (Dummy)", Index: 76
2020-04-20 12:04:04.241 Status: dzVents: Debug: Push to Influx: Device KWH Garage was changed 2.900
2020-04-20 12:04:04.242 Status: dzVents: Debug: Push to Influx: Too soon after last update; we don't want an endless loop
2020-04-20 12:04:04.244 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
2020-04-20 12:04:04.693 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "Vermogen Garage (Dummy)", Index: 79
2020-04-20 12:04:04.695 Status: dzVents: Debug: Push to Influx: Device Vermogen Garage was changed 2223
2020-04-20 12:04:04.695 Status: dzVents: Debug: Push to Influx: Too soon after last update; we don't want an endless loop
2020-04-20 12:04:04.697 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
2020-04-20 12:05:01.377 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-04-20 12:05:02.797 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-04-20 12:05:05.651 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "WP Opgewekt (Dummy)", Index: 64
2020-04-20 12:05:05.652 Status: dzVents: Debug: Push to Influx: Device WP Opgewekt was changed 621.0
2020-04-20 12:05:05.653 Status: dzVents: Debug: Push to Influx: OpenURL: url = http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=64&nvalue=0&svalue=621.0;2303871.6167065
2020-04-20 12:05:05.653 Status: dzVents: Debug: Push to Influx: OpenURL: method = GET
2020-04-20 12:05:05.653 Status: dzVents: Debug: Push to Influx: OpenURL: post data = nil
2020-04-20 12:05:05.653 Status: dzVents: Debug: Push to Influx: OpenURL: headers = nil
2020-04-20 12:05:05.654 Status: dzVents: Debug: Push to Influx: OpenURL: callback = nil
2020-04-20 12:05:05.656 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
2020-04-20 12:05:05.666 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "WP COP (Dummy)", Index: 73
2020-04-20 12:05:05.668 Status: dzVents: Debug: Push to Influx: Device WP COP was changed 6.21
2020-04-20 12:05:05.668 Status: dzVents: Debug: Push to Influx: OpenURL: url = http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=73&nvalue=0&svalue=6.21
2020-04-20 12:05:05.668 Status: dzVents: Debug: Push to Influx: OpenURL: method = GET
2020-04-20 12:05:05.669 Status: dzVents: Debug: Push to Influx: OpenURL: post data = nil
2020-04-20 12:05:05.669 Status: dzVents: Debug: Push to Influx: OpenURL: headers = nil
2020-04-20 12:05:05.669 Status: dzVents: Debug: Push to Influx: OpenURL: callback = nil
2020-04-20 12:05:05.672 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
2020-04-20 12:05:05.677 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "KWH Garage (Dummy)", Index: 76
2020-04-20 12:05:05.679 Status: dzVents: Debug: Push to Influx: Device KWH Garage was changed 2.900
2020-04-20 12:05:05.679 Status: dzVents: Debug: Push to Influx: OpenURL: url = http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=76&nvalue=0&svalue=2.900
2020-04-20 12:05:05.679 Status: dzVents: Debug: Push to Influx: OpenURL: method = GET
2020-04-20 12:05:05.679 Status: dzVents: Debug: Push to Influx: OpenURL: post data = nil
2020-04-20 12:05:05.680 Status: dzVents: Debug: Push to Influx: OpenURL: headers = nil
2020-04-20 12:05:05.680 Status: dzVents: Debug: Push to Influx: OpenURL: callback = nil
2020-04-20 12:05:05.683 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
2020-04-20 12:05:05.689 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "Vermogen Garage (Dummy)", Index: 79
2020-04-20 12:05:05.692 Status: dzVents: Debug: Push to Influx: Device Vermogen Garage was changed 2215
2020-04-20 12:05:05.692 Status: dzVents: Debug: Push to Influx: OpenURL: url = http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=79&nvalue=0&svalue=2215
2020-04-20 12:05:05.693 Status: dzVents: Debug: Push to Influx: OpenURL: method = GET
2020-04-20 12:05:05.693 Status: dzVents: Debug: Push to Influx: OpenURL: post data = nil
2020-04-20 12:05:05.693 Status: dzVents: Debug: Push to Influx: OpenURL: headers = nil
2020-04-20 12:05:05.693 Status: dzVents: Debug: Push to Influx: OpenURL: callback = nil
2020-04-20 12:05:05.697 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
2020-04-20 12:05:05.709 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-04-20 12:05:06.145 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "PV Vermogen Sauna (Dummy)", Index: 33
2020-04-20 12:05:06.147 Status: dzVents: Debug: Push to Influx: Device PV Vermogen Sauna was changed 1913
2020-04-20 12:05:06.147 Status: dzVents: Debug: Push to Influx: OpenURL: url = http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=33&nvalue=0&svalue=1913;5050.0
2020-04-20 12:05:06.147 Status: dzVents: Debug: Push to Influx: OpenURL: method = GET
2020-04-20 12:05:06.147 Status: dzVents: Debug: Push to Influx: OpenURL: post data = nil
2020-04-20 12:05:06.148 Status: dzVents: Debug: Push to Influx: OpenURL: headers = nil
2020-04-20 12:05:06.148 Status: dzVents: Debug: Push to Influx: OpenURL: callback = nil
2020-04-20 12:05:06.151 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
2020-04-20 12:05:06.151 Status: dzVents: Info: Som PV panelen: ------ Start internal script: PV som vermogen: Device: "PV Vermogen Sauna (Dummy)", Index: 33
2020-04-20 12:05:06.156 Status: dzVents: Debug: Som PV panelen: Processing device-adapter for PV Vermogen Garage: kWh device adapter
2020-04-20 12:05:06.160 Status: dzVents: Debug: Som PV panelen: Processing device-adapter for PV Vermogen Totaal: kWh device adapter
2020-04-20 12:05:06.165 Status: dzVents: Debug: Som PV panelen: Processing device-adapter for KWH Garage: Custom sensor device adapter
2020-04-20 12:05:06.169 Status: dzVents: Debug: Som PV panelen: Processing device-adapter for KWH totaal: Custom sensor device adapter
2020-04-20 12:05:06.170 Status: dzVents: Info: Som PV panelen: ------ Finished PV som vermogen
2020-04-20 12:05:06.196 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-04-20 12:05:06.666 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "PV Vermogen Sauna (Dummy)", Index: 33
2020-04-20 12:05:06.668 Status: dzVents: Debug: Push to Influx: Device PV Vermogen Sauna was changed 1913
2020-04-20 12:05:06.669 Status: dzVents: Debug: Push to Influx: Too soon after last update; we don't want an endless loop
2020-04-20 12:05:06.671 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
2020-04-20 12:05:06.671 Status: dzVents: Info: Som PV panelen: ------ Start internal script: PV som vermogen: Device: "PV Vermogen Sauna (Dummy)", Index: 33
2020-04-20 12:05:06.676 Status: dzVents: Debug: Som PV panelen: Processing device-adapter for PV Vermogen Garage: kWh device adapter
2020-04-20 12:05:06.682 Status: dzVents: Debug: Som PV panelen: Processing device-adapter for PV Vermogen Totaal: kWh device adapter
2020-04-20 12:05:06.690 Status: dzVents: Debug: Som PV panelen: Processing device-adapter for KWH Garage: Custom sensor device adapter
2020-04-20 12:05:06.695 Status: dzVents: Debug: Som PV panelen: Processing device-adapter for KWH totaal: Custom sensor device adapter
2020-04-20 12:05:06.697 Status: dzVents: Info: Som PV panelen: ------ Finished PV som vermogen
2020-04-20 12:05:06.702 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "WP Opgewekt (Dummy)", Index: 64
2020-04-20 12:05:06.704 Status: dzVents: Debug: Push to Influx: Device WP Opgewekt was changed 621.0
2020-04-20 12:05:06.704 Status: dzVents: Debug: Push to Influx: Too soon after last update; we don't want an endless loop
2020-04-20 12:05:06.706 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
2020-04-20 12:05:06.712 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "WP COP (Dummy)", Index: 73
2020-04-20 12:05:06.714 Status: dzVents: Debug: Push to Influx: Device WP COP was changed 6.21
2020-04-20 12:05:06.714 Status: dzVents: Debug: Push to Influx: Too soon after last update; we don't want an endless loop
2020-04-20 12:05:06.717 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
2020-04-20 12:05:06.718 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "KWH Garage (Dummy)", Index: 76
2020-04-20 12:05:06.720 Status: dzVents: Debug: Push to Influx: Device KWH Garage was changed 2.900
2020-04-20 12:05:06.720 Status: dzVents: Debug: Push to Influx: Too soon after last update; we don't want an endless loop
2020-04-20 12:05:06.723 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
2020-04-20 12:05:06.727 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "Vermogen Garage (Dummy)", Index: 79
2020-04-20 12:05:06.729 Status: dzVents: Debug: Push to Influx: Device Vermogen Garage was changed 2215
2020-04-20 12:05:06.729 Status: dzVents: Debug: Push to Influx: Too soon after last update; we don't want an endless loop
2020-04-20 12:05:06.731 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
2020-04-20 12:05:06.733 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-04-20 12:05:07.127 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "PV Vermogen Totaal (Dummy)", Index: 29
2020-04-20 12:05:07.129 Status: dzVents: Debug: Push to Influx: Device PV Vermogen Totaal was changed 4128.0
2020-04-20 12:05:07.129 Status: dzVents: Debug: Push to Influx: OpenURL: url = http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=29&nvalue=0&svalue=4128.0;7950.0
2020-04-20 12:05:07.129 Status: dzVents: Debug: Push to Influx: OpenURL: method = GET
2020-04-20 12:05:07.130 Status: dzVents: Debug: Push to Influx: OpenURL: post data = nil
2020-04-20 12:05:07.130 Status: dzVents: Debug: Push to Influx: OpenURL: headers = nil
2020-04-20 12:05:07.130 Status: dzVents: Debug: Push to Influx: OpenURL: callback = nil
2020-04-20 12:05:07.133 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
2020-04-20 12:05:07.140 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "KWH totaal (Dummy)", Index: 77
2020-04-20 12:05:07.142 Status: dzVents: Debug: Push to Influx: Device KWH totaal was changed 7.95
2020-04-20 12:05:07.142 Status: dzVents: Debug: Push to Influx: OpenURL: url = http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=77&nvalue=0&svalue=7.95
2020-04-20 12:05:07.142 Status: dzVents: Debug: Push to Influx: OpenURL: method = GET
2020-04-20 12:05:07.143 Status: dzVents: Debug: Push to Influx: OpenURL: post data = nil
2020-04-20 12:05:07.143 Status: dzVents: Debug: Push to Influx: OpenURL: headers = nil
2020-04-20 12:05:07.143 Status: dzVents: Debug: Push to Influx: OpenURL: callback = nil
2020-04-20 12:05:07.146 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
2020-04-20 12:05:07.151 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-04-20 12:05:07.627 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "PV Vermogen Totaal (Dummy)", Index: 29
2020-04-20 12:05:07.632 Status: dzVents: Debug: Push to Influx: Device PV Vermogen Totaal was changed 4128.0
2020-04-20 12:05:07.632 Status: dzVents: Debug: Push to Influx: Too soon after last update; we don't want an endless loop
2020-04-20 12:05:07.634 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
2020-04-20 12:05:07.639 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "KWH totaal (Dummy)", Index: 77
2020-04-20 12:05:07.641 Status: dzVents: Debug: Push to Influx: Device KWH totaal was changed 7.95
2020-04-20 12:05:07.641 Status: dzVents: Debug: Push to Influx: Too soon after last update; we don't want an endless loop
2020-04-20 12:05:07.644 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
What I also have seen this morning in the error loggings the message "2020-04-20 06:15:52.540 Error: EventSystem: Warning!, lua script /home/pi/domoticz/dzVents/runtime/dzVents.lua has been running for more than 10 seconds" I can.t see which event it is but I expect the push to influx could be the course.
What should I change to prevent both errors?
Re: Values are not sent to influxdb
Posted: Monday 20 April 2020 13:47
by waaren
MeAlbert wrote: ↑Monday 20 April 2020 12:50
The script is working fine but I see two things happening I would like to prevent from happening.
What should I change to prevent both errors?
The messages from the script are debug messages and can be suppressed by changing the line domoticz.LOG_DEBUG to domoticz.LOG_ERROR.
After you have done that these messages will not show in your log.
The message "has been running for more than 10 seconds" will most likely not come from the push script. The script normally finish in less then 0.01 seconds and there is nothing in the script waiting for something to finish.
Normally this happens when a script it blocked because of a wait for a response from the OS. So if you have a script with os.execute or io.popen and the command is not send to the background using the & at the end of the command string that would be a candidate.
Can you also please update your profile and add which version you are on ? Or mention it on every post you make.
Re: Values are not sent to influxdb
Posted: Tuesday 21 April 2020 0:38
by MeAlbert
Have changed my profile. Use 2020.1.
I have no os.execute or io.popen commands in scripts running. Time it happens is also the time Domoticz crashes some times. 05:10 and last two times 06:10.
Trying to fix that but do not know how to yet.
Your reaction on the debug message is correct but if the script is started by device 80 it pushes the value to influx but the fact that you get an error message too soon etc means that he started again with device 80. Or in the logging. First push 29, then 77 and the 29 again too soon after and then 77 again too soon. For me it means the script starts because 29 changes, then because also 77 changes. But it is not possible that 29 changes again so fast (1 minute interval) so something is triggering it again with the 2 error messages as result. If you leave out the error message the behavior is still there.
Re: Values are not sent to influxdb
Posted: Tuesday 21 April 2020 0:57
by waaren
MeAlbert wrote: ↑Tuesday 21 April 2020 0:38
For me it means the script starts because 29 changes, then because also 77 changes. But it is not possible that 29 changes again so fast (1 minute interval) so something is triggering it again with the 2 error messages as result. If you leave out the error message the behavior is still there.
Understand now that you are using the script to push data from multiple devices. Probably the script needs some adjustments because of that. If you send the script as you have it now, I will have a look.
Re: Values are not sent to influxdb
Posted: Wednesday 22 April 2020 17:22
by MeAlbert
Sorry I was not clear in that. But I use it for multiple devices after you said I could do so.
Here is the script:
Code: Select all
return
{
on =
{
devices =
{
64, 73, 29, 33, 76, 77, 79, 80
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Push to Influx',
},
data =
{
lastExecutionTimes = { initial = {} },
},
execute = function(dz, item)
dz.log('Device ' .. item.name .. ' was changed ' .. item.rawData[1], dz.LOG_DEBUG)
local function pushToInfluxdb(idx , nValue, rawData )
local sValue = table.concat(rawData,';')
local nValue = nValue or 0
local url = dz.settings['Domoticz url'] .. '/json.htm?type=command¶m=udevice&idx=' .. idx ..
'&nvalue=' .. nValue ..
'&svalue=' .. sValue
dz.openURL(url)
end
if dz.data.lastExecutionTimes[item.name] == nil or ( dz.data.lastExecutionTimes[item.name] < ( dz.time.dDate - 1 ) ) then
pushToInfluxdb( item.idx, 0, item.rawData )
dz.data.lastExecutionTimes[item.name] = dz.time.dDate
else
dz.log('Too soon after last update; we don\'t want an endless loop', dz.LOG_DEBUG)
end
end
}
Re: Values are not sent to influxdb
Posted: Wednesday 22 April 2020 17:47
by waaren
MeAlbert wrote: ↑Wednesday 22 April 2020 17:22
Sorry I was not clear in that. But I use it for multiple devices after you said I could do so.
This version of the script should already take care of multiple devices.
Can you please add
Code: Select all
dz.log(dz.data.lastExecutionTimes, dz.LOG_DEBUG)
at line 37 and at line 44 of the script ?
It could be that the script looks at an old data file. if that's the case you can first look into that file with
Code: Select all
sudo cat <domoticz dir>/scripts/dzVents/data/__data_<scriptname>.lua
and remove the file with
Code: Select all
sudo rm <domoticz dir>/scripts/dzVents/data/__data_<scriptname>.lua
The script will rebuild it on the next execution.
Re: Values are not sent to influxdb
Posted: Wednesday 22 April 2020 22:51
by MeAlbert
I hope I put it on the right place.
Code: Select all
dz.log(dz.data.lastExecutionTimes, dz.LOG_DEBUG)
if dz.data.lastExecutionTimes[item.name] == nil or ( dz.data.lastExecutionTimes[item.name] < ( dz.time.dDate - 1 ) ) then
pushToInfluxdb( item.idx, 0, item.rawData )
dz.data.lastExecutionTimes[item.name] = dz.time.dDate
else
dz.log('Too soon after last update; we don\'t want an endless loop', dz.LOG_DEBUG)
end
dz.log(dz.data.lastExecutionTimes, dz.LOG_DEBUG)
end
}
The logfile looks like this now:
Code: Select all
2020-04-22 22:45:03.444 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "WP Opgewekt (Dummy)", Index: 64
2020-04-22 22:45:03.445 Status: dzVents: Debug: Push to Influx: Device WP Opgewekt was changed 569.0
2020-04-22 22:45:03.446 Status: dzVents: Debug: Push to Influx: {["KWH Garage vandaag"]=1587580083, ["WP COP"]=1587588003, ["WP Opgewekt"]=1587588242, ["KWH totaal vandaag"]=1587585607, ["PV Vermogen Sauna"]=1587585604, ["KWH Garage"]=1587389343, ["PV Sauna vandaag"]=1587215107, ["PV Vermogen Garage"]=1587585604, ["KWH totaal"]=1587389108, ["PV Vermogen Totaal"]=1587585605, ["Vermogen Garage"]=1587580083, ["WP Backup Heater"]=1585326248}
2020-04-22 22:45:03.447 Status: dzVents: Debug: Push to Influx: OpenURL: url = http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=64&nvalue=0&svalue=569.0;2355172.5667101
2020-04-22 22:45:03.447 Status: dzVents: Debug: Push to Influx: OpenURL: method = GET
2020-04-22 22:45:03.447 Status: dzVents: Debug: Push to Influx: OpenURL: post data = nil
2020-04-22 22:45:03.447 Status: dzVents: Debug: Push to Influx: OpenURL: headers = nil
2020-04-22 22:45:03.448 Status: dzVents: Debug: Push to Influx: OpenURL: callback = nil
2020-04-22 22:45:03.461 Status: dzVents: Debug: Push to Influx: {["KWH Garage vandaag"]=1587580083, ["WP COP"]=1587588003, ["WP Opgewekt"]=1587588303, ["KWH totaal vandaag"]=1587585607, ["PV Vermogen Sauna"]=1587585604, ["KWH Garage"]=1587389343, ["PV Sauna vandaag"]=1587215107, ["PV Vermogen Garage"]=1587585604, ["KWH totaal"]=1587389108, ["PV Vermogen Totaal"]=1587585605, ["Vermogen Garage"]=1587580083, ["WP Backup Heater"]=1585326248}
2020-04-22 22:45:03.468 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
2020-04-22 22:45:03.489 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "WP COP (Dummy)", Index: 73
2020-04-22 22:45:03.491 Status: dzVents: Debug: Push to Influx: Device WP COP was changed 10.31
2020-04-22 22:45:03.491 Status: dzVents: Debug: Push to Influx: {["KWH Garage vandaag"]=1587580083, ["WP COP"]=1587588003, ["WP Opgewekt"]=1587588303, ["KWH totaal vandaag"]=1587585607, ["PV Vermogen Sauna"]=1587585604, ["KWH Garage"]=1587389343, ["PV Sauna vandaag"]=1587215107, ["WP Backup Heater"]=1585326248, ["KWH totaal"]=1587389108, ["Vermogen Garage"]=1587580083, ["PV Vermogen Totaal"]=1587585605, ["PV Vermogen Garage"]=1587585604}
2020-04-22 22:45:03.492 Status: dzVents: Debug: Push to Influx: OpenURL: url = http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=73&nvalue=0&svalue=10.31
2020-04-22 22:45:03.492 Status: dzVents: Debug: Push to Influx: OpenURL: method = GET
2020-04-22 22:45:03.492 Status: dzVents: Debug: Push to Influx: OpenURL: post data = nil
2020-04-22 22:45:03.493 Status: dzVents: Debug: Push to Influx: OpenURL: headers = nil
2020-04-22 22:45:03.493 Status: dzVents: Debug: Push to Influx: OpenURL: callback = nil
2020-04-22 22:45:03.494 Status: dzVents: Debug: Push to Influx: {["KWH Garage vandaag"]=1587580083, ["WP COP"]=1587588303, ["WP Opgewekt"]=1587588303, ["KWH totaal vandaag"]=1587585607, ["PV Vermogen Sauna"]=1587585604, ["KWH Garage"]=1587389343, ["PV Sauna vandaag"]=1587215107, ["WP Backup Heater"]=1585326248, ["KWH totaal"]=1587389108, ["Vermogen Garage"]=1587580083, ["PV Vermogen Totaal"]=1587585605, ["PV Vermogen Garage"]=1587585604}
2020-04-22 22:45:03.502 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
2020-04-22 22:45:03.509 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-04-22 22:45:04.230 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "WP Opgewekt (Dummy)", Index: 64
2020-04-22 22:45:04.232 Status: dzVents: Debug: Push to Influx: Device WP Opgewekt was changed 569.0
2020-04-22 22:45:04.233 Status: dzVents: Debug: Push to Influx: {["PV Sauna vandaag"]=1587215107, ["PV Vermogen Sauna"]=1587585604, ["WP Backup Heater"]=1585326248, ["WP COP"]=1587588303, ["WP Opgewekt"]=1587588303, ["KWH totaal vandaag"]=1587585607, ["PV Vermogen Garage"]=1587585604, ["PV Vermogen Totaal"]=1587585605, ["KWH totaal"]=1587389108, ["KWH Garage"]=1587389343, ["KWH Garage vandaag"]=1587580083, ["Vermogen Garage"]=1587580083}
2020-04-22 22:45:04.233 Status: dzVents: Debug: Push to Influx: Too soon after last update; we don't want an endless loop
2020-04-22 22:45:04.234 Status: dzVents: Debug: Push to Influx: {["PV Sauna vandaag"]=1587215107, ["PV Vermogen Sauna"]=1587585604, ["WP Backup Heater"]=1585326248, ["WP COP"]=1587588303, ["WP Opgewekt"]=1587588303, ["KWH totaal vandaag"]=1587585607, ["PV Vermogen Garage"]=1587585604, ["PV Vermogen Totaal"]=1587585605, ["KWH totaal"]=1587389108, ["KWH Garage"]=1587389343, ["KWH Garage vandaag"]=1587580083, ["Vermogen Garage"]=1587580083}
2020-04-22 22:45:04.236 Status: dzVents: Info: Push to Influx: ------ Finished Push naar influx
2020-04-22 22:45:04.685 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "WP COP (Dummy)", Index: 73
Interesting to see it puts every value twice which explains the error message. But you can see that better.
Re: Values are not sent to influxdb
Posted: Thursday 23 April 2020 0:30
by waaren
MeAlbert wrote: ↑Wednesday 22 April 2020 22:51
I hope I put it on the right place.
The logfile looks like this now:
Code: Select all
2020-04-22 22:45:03.444 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "WP Opgewekt (Dummy)", Index: 64
2020-04-22 22:45:04.230 Status: dzVents: Info: Push to Influx: ------ Start internal script: Push naar influx: Device: "WP Opgewekt (Dummy)", Index: 64
Yes these lines are on the right place but can now be removed as they confirm what I wanted to doublecheck.
If you look at the above two lines in the code window you will see that device WP Opgewekt (Dummy) triggered the script twice. First time because of the real update and the second time because the script itself forced it by the JSON command udevice. The JSON command will ensure the values are pushed to influx but will also cause an event trigger that starts the script again.
So the second time the script should indeed ignore this update and it does. The message "too soon" is only there during debug mode and now served it's purpose. You can change the line domoticz.LOG_DEBUG to domoticz.LOG_ERROR and you wont see this confimation that the script logic works as designed.
Re: Values are not sent to influxdb
Posted: Friday 01 May 2020 12:14
by Number8
I noticed that 2020.x build featuring dzvents v3 supports sending values to influxdb using dz.devices().update. Thank you to developers.
Re: Values are not sent to influxdb
Posted: Friday 17 July 2020 15:55
by Tehlo
Hi, first of all, I am a major noob at programming/coding and basically am trying to understand scripts I found online to use with my P1 Monitor.
I found this script which logs data nicely, but it is having the issue where the data cannot be sent to Influx.
Great to hear that the devs fixed this, but I have no clue on how to properly add these new features to my script so that the data does get sent to Influx properly. This is my code, any idea?
Code: Select all
--[[
dzVents script dzVents script time
om P1 Smart Meter Elektriciteitswaarde te ontleden in afzonderlijke Meterstanden.
Houd er rekening mee dat de teller van vandaag aanvankelijk tot de volgende dag bij de GUI een verkeerde waarde zal weergeven.
Script gedownload van huizebruin.nl
huizebruin.nl/domoticz/slimme-meter-(p1)-opsplitsen-naar-4-tellers-domoticz-met-lua
Te gebruiken voor domoticz versie >= V4.11305
]] --
local fetchIntervalMins = 1 -- (Geheel) Minutenfrequentie van deze scriptuitvoering 1 = elke minuut, 10 = elke 10 minuten, enz.) Moet een van (1,2,3,4,5,6,10,12,15,20,30) zijn.
local ScriptVersion = '3.0.9'
return {
on = {
timer = { 'every ' .. fetchIntervalMins .. ' minutes' }
},
logging = {
level = domoticz.LOG_DEBUG, -- Maak commentaar op deze regel om de instelling van dzVents global logging te overschrijven
marker = 'Afzonderlijke Meterstanden '.. ScriptVersion
},
data = { lastP1 = { initial = {} }},
execute = function(dz, item)
-- Voeg apparaatnamen toe tussen aanhalingstekens of apparaat-idx zonder aanhalingstekens
local P1 = dz.devices('Power') -- Electra, P1 Smart Meter device (idx of "name") (verplicht)
--[[ Voer namen / idx in voor apparaten die je wilt onder deze commentaarregels
Deze apparaten moeten worden gemaakt als nieuwe incrementele tellers. Script kan verkeerde waarden opleveren
bij gebruik met bestaande die al waarden bevatten
De resterende regels kunnen worden verwijderd of becommentarieerd
]]--
local usageLow = dz.devices('Verbruik Laag') -- Meter gebruik laag, virtueel apparaat, teller incrementeel
local usageHigh = dz.devices('Verbruik Hoog')
local usageTotal = dz.devices('Verbruik Totaal')-- Meter gebruik Hoog, Virtueel apparaat, teller incrementeel
--local returnLow = dz.devices('Teruglevering Laag') -- Meter Return Laag, Virtueel apparaat, teller incrementeel
--local returnHigh = dz.devices('Teruglevering Hoog') -- Meter Return Hoog, Virtueel apparaat, teller incrementeel
-- Onder deze regel zijn geen wijzigingen vereist ---
lastP1 = dz.data.lastP1
local function updateCounter(dv, value, previousValue )
if not(dv) then return end
if not(previousValue) then
dz.log("Geen eerdere gegevens voor " .. dv.name .. " nog; deze run overslaan",dz.LOG_DEBUG)
return
end
if dv.counter ~= 0 then
value = value - previousValue
end
dv.updateCounter(value)
dz.log("Increment " .. dv.name .. " with: " .. value,dz.LOG_DEBUG)
end
-- Update the device
updateCounter(usageLow, P1.usage1, lastP1.usage1)
updateCounter(usageHigh, P1.usage2, lastP1.usage2)
updateCounter(usageTotal, P1.usage1 + P1.usage2, lastP1.usage1 + lastP1.usage2)
--updateCounter(returnLow, P1.return1, lastP1.return1)
--updateCounter(returnHigh, P1.return2, lastP1.return2)
lastP1.usage1 = P1.usage1
lastP1.usage2 = P1.usage2
--lastP1.return1 = P1.return1
--lastP1.return2 = P1.return2
end
}
Thanks in advance, I'm more than willing to learn so if anyone could explain/help out that would be much appreciated! <3
Re: Values are not sent to influxdb
Posted: Friday 17 July 2020 16:14
by Number8
Hello Tehlo
There are several problems in the function updateCounter. Don't try to make a function but update device value directly in the main section of the code and then when it works you can develop the function step by step.
So depending on the type of counter you want to update syntax varies slightly. For a basic counter updating the value (overwriting), syntax is
Code: Select all
dz.devices(IDX).updateCounter(value)
Please have a look at
https://www.domoticz.com/wiki/DzVents:_ ... ncremental
Re: Values are not sent to influxdb
Posted: Friday 17 July 2020 16:44
by Tehlo
@Number8
Yeaaaah...
This is a lot of fun lol. Thanks for the information and article! I have messaged around with it for a bit but I have horridly broken it now! Yay!
https://imgur.com/a/MicfIuc
It used to be at 200kWh before I started ;p
Set the code to this:
local usageTotal = dz.devices('Verbruik Totaal').updateCounter (P1.usage1 + P1.usage2)
Any idea on what could be going wrong?
(I tried with incrementCounter too but that didn't work either)
Re: Values are not sent to influxdb
Posted: Friday 17 July 2020 19:15
by Number8
@Tehlo: as a good pratice I would recommend using IDX (that you may find in Setup/Devices) instead of the name of the device. You could very well change the name of the device and the code would be broken. Just to make sure I understand the issue: are you still having an issue with influxdb update or do you have also an issue with device update?
What version of dzvents are you using?
In any case if the device as the code suggest is a P1 smartmeter the syntax is:
Code: Select all
updateP1(usage1, usage2, return1, return2, cons, prod)
Re: Values are not sent to influxdb
Posted: Sunday 16 October 2022 10:34
by NvBgm55
I have read this topic with great interest and as a newbie to Dzvents scripting. I've tried to run the script discussed here, but it doesn't work. What I want to do with the script is the following. I have a script for 'Gas per Degree Day' that I want to send the value to influx. The value appears in a dummy sensor in Domoticz. Because I can't find this dummy in send data within Domoticz, I wanted to do that with this script. Now my problem. On line 30 I get a "status" : "ERR" and I've been trying to figure out why for days... For some reason I can't get a value .
Code: Select all
return
{
on =
{
devices =
{
113
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Push to Influx',
},
data =
{
lastExecutionTimes = { initial = {} },
},
execute = function(dz, item)
dz.log('Device ' .. item.name .. ' was changed ' .. item.rawData[1], dz.LOG_DEBUG)
local function pushToInfluxdb(idx , nValue, rawData )
local sValue = table.concat(rawData,';')
local nValue = nValue or 0
local url = dz.settings['192.168.x.xx:xxxx'] .. '/json.htm?type=command¶m=udevice&idx=' .. idx ..
'&nvalue=' .. nValue ..
'&svalue=' .. sValue
dz.openURL(url)
end
if dz.data.lastExecutionTimes[item.name] == nil or ( dz.data.lastExecutionTimes[item.name] < ( dz.time.dDate - 1 ) ) then
pushToInfluxdb( item.idx, 0, item.rawData )
dz.data.lastExecutionTimes[item.name] = dz.time.dDate
else
dz.log('Too soon after last update; we don\'t want an endless loop', dz.LOG_DEBUG)
end
end
}