logo elektroda
logo elektroda
X
logo elektroda

Useful scripts for Domoticz. Dzvent''''s, LUA, Node Red, etc.

xury 30408 39
ADVERTISEMENT
This content has been translated flag-pl » flag-en View the original version here
  • #31 20804762
    Maciek1008
    Level 11  
    These are incremental meters of the Water type.
    IDX of the water main meter: 871
    IDX of garden water meter: 1146
    IDX of water meter to be calculated: 1164
    According to the IDX the script has to calculate: 871 - 1146 = 1164
  • ADVERTISEMENT
  • ADVERTISEMENT
  • #34 21378916
    Daro1003
    Level 34  
    Is there a chance to write a script that controls the heater based on data from the photovoltaics and current power consumption data in the house ?
  • #35 21441441
    sznickers
    Level 11  
    Hi, @xury very cool post. Thanks.
    Domoticz saves the parameters every 5 minutes. Is it possible to change it to do a save every 5 seconds for example? Why? I would like to know at night if the sump pump is switched on. If the recording is every 5 minutes, it can be missed - i.e. it won't record. The time it takes for the pump to run in one cycle is about 1-2 minutes.
  • ADVERTISEMENT
  • #36 21444762
    xury
    Automation specialist
    It is not possible to change the time of writing to the database without interfering with the source code and your own compilation.
    Instead, you can write at arbitrary intervals to the Influxdb database and then visualise this data on Grafana.
  • #38 21446908
    xury
    Automation specialist
    Helpful, I used to use it myself. If your sensor reports its values frequently to Domoticz
  • ADVERTISEMENT
  • #39 21447539
    sznickers
    Level 11  
    Maybe you could help :) , I have one small error:

    2025-02-19 22:40:00.579 Error: EventSystem: in LCD Falownik Lua all: [string "commandArray = {} ..."]:4: bad argument #1 to 'pairs' (table expected, got nil)
    2025-02-19 22:41:00.471 Error: EventSystem: in LCD Inverter Lua all: [string "commandArray = {} ..."]:4: bad argument #1 to 'pairs' (table expected, got nil)
    2025-02-19 22:42:00.522 Error: EventSystem: in LCD Inverter Lua all: [string "commandArray = {} ..."]:4: bad argument #1 to 'pairs' (table expected, got nil)
    2025-02-19 22:43:00.544 Error: EventSystem: in LCD Inverter Lua all: [string "commandArray = {} ..."]:4: bad argument #1 to 'pairs' (table expected, got nil)

    What does he mean by pairs, table?
    I've made a script to send data from the sensor to the ESP to the display. The script works, it displays what it is supposed to display on the display.

    my script:
    commandArray = {}
    
    -- loop through all the changed devices
    for deviceName,deviceValue in pairs(devicechanged) do
    
       if (deviceName=='L123FW') then
         commandArray['OpenURL']='http://192.168.0.113/control?cmd=LCD,1,1,'..tostring(deviceValue)..'_W'
       end
        if (deviceName=='L123FkWh') then
         commandArray['OpenURL']='http://192.168.0.113/control?cmd=LCD,2,1,'..tostring(deviceValue)..'_kWh'
       end
    
    end
    
    return commandArray
    .

    and this is the LUA script all instructions:
    commandArray = {}
    
    print ("All based event fired");
    -- loop through all the devices
    for deviceName,deviceValue in pairs(otherdevices) do
    --    if (deviceName=='myDevice') then
    --        if deviceValue == "On" then
    --            print("Device is On")
    --        elseif deviceValue == "Off" then
    --            commandArray['a device name'] = "On"
    --            commandArray['Scene:MyScene'] = "Off"
    --        end
    --    end
    end
    
    -- loop through all the variables
    for variableName,variableValue in pairs(uservariables) do
    --    if (variableName=='myVariable') then
    --        if variableValue == 1 then
    --            commandArray['a device name'] = "On"
    --            commandArray['Group:My Group'] = "Off AFTER 30"
    --        end
    --    end
    end
    .

FAQ

TL;DR: Domoticz writes new sensor values to its internal SQLite database every 5 minutes [Elektroda, xury, post #21444762] “Writing faster than 5 minutes needs source recompilation” [Elektroda, xury, post #21444762]

Why it matters: knowing native limits avoids unnecessary SD-card wear and lost datapoints.

Quick Facts

• Default Domoticz database commit interval: 300 s (fixed) [Elektroda, xury, post #21444762] • dzVents ‘every minute’ timer fires 1 440 times per day [dzVents Wiki] • PZEM-004T measures 0–20 A RMS, ±1% typical accuracy (PZEM-004T v3 datasheet) • Sonoff Basic relay handles 10 A/2.2 kW, price ≈ US $6 [ITEAD, 2024] • Telegram Bot API needs Chat ID + Token; no RPi app required [Elektroda, xury, post #17946092]

How do I make Domoticz log data faster than every 5 minutes?

You can’t change the 5-minute commit interval from the GUI. The scheduler is hard-coded; faster logging needs you to modify main/Domoticz.cpp and re-compile, or bypass Domoticz by pushing values directly to InfluxDB or MQTT [Elektroda, xury, post #21444762]

Where should I install Telegram for push notifications?

Install Telegram only on your phone. In Domoticz, create a Bot, note the Chat ID and API Token, and enter them under Setup → Notifications. The RPi just calls the HTTPS endpoint; no local Telegram app is necessary [Elektroda, xury, post #17946092]

I get “bad argument #1 to 'pairs' (table expected, got nil)’ in a Lua script. Why?

The devicechanged or uservariables table is nil in All-Events context. Wrap the loop in if devicechanged then … end, or switch the script type to ‘Device’ so the engine populates those tables [Elektroda, sznickers, post #21447539]

How can I subtract two water-meter readings in dzVents?

Create a Dummy ‘Water’ counter for the result, then add a script:

return {
on = { timer = { 'every minute' } },
execute = function(dz)
local main = dz.devices(871).counter
local lawn = dz.devices(1146).counter
dz.devices(1164).updateCounter(main - lawn)
end
}
Replace the IDX numbers if they differ [Elektroda, Maciek1008, post #20804762]

How do I merge three PZEM-004T phase currents into one graph?

Use device.updateCurrent(L1,L2,L3) in dzVents. Example shown by xury consolidates IDX 5-7 into IDX 16 and updates every new value [Elektroda, xury, post #17750955]

Can I overlay live sensor text on a Hikvision camera?

Yes. Send an HTTP PUT with XML payload to /ISAPI/System/Video/inputs/channels/1/overlays using digest auth. Node-RED flow in the thread updates two temperature strings every minute [Elektroda, xury, post #19193707]

What’s the quickest way to capture a doorbell video and push it to Telegram?

  1. Install ffmpeg on the RPi. 2. Save the provided doorbell.sh script with execution rights. 3. Add the dzVents script that runs os.execute('/home/pi/domoticz/scripts/doorbell.sh') when device ‘Dzwonek’ turns ON. The script records 5 s RTSP clip and posts it via Telegram Bot API [Elektroda, xury, post #17941615]

How can I power-on an Android TV from Node-RED?

Enable USB debugging on the TV, install adb on the server, then use an Exec node: etherwake -i <iface> <MAC> && adb connect <IP>:5555 && adb shell input keyevent KEYCODE_POWER. Flow by xury also maps D-Pad and volume keys to Nora scenes for voice control [Elektroda, xury, post #18620730]

Is there a way to stop Victron PV inverters during negative price hours?

Yes. Monitor day-ahead price API, and when price < 0, publish ESS_OVERRIDE=1 and STATE=2 via MQTT to Victron’s Venus OS. The shared Node-RED flow blocks export and resumes when prices normalize [Elektroda, xury, post #21467173]

Edge case: What happens if Domoticz misses a 1-minute PIR event?

Because Domoticz logs every 5 minutes, a PIR that switches ON and OFF within that window may not appear in the history. “If the pump runs only 1–2 minutes it can be missed” [Elektroda, sznickers, post #21441441] Use InfluxDB or a dzVents HTTP call for higher-resolution logging.
Generated by the language model.
ADVERTISEMENT