Script: Re-program Z-Wave node if it fails to report power usage

Moderator: leecollings

Post Reply
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Script: Re-program Z-Wave node if it fails to report power usage

Post by ben53252642 »

This script checks if a Z-Wave device has failed to report kWh watts for more than 5 minutes.

If the check fails and Domoticz has been up for more than 10 minutes, it re-programs the Z-Wave node.

I used Chrome inspect when submitting Z-Wave values for a device, in this case a "Aeotec ZW096 Smart Switch 6" to get the payload used in the script.

See here for more details
https://www.domoticz.com/wiki/Domoticz_ ... ve_devices

Lua script, type is: Time

Code: Select all

-- Device Last Updates
t1 = os.time()
    devices = {
        "Microwave kWh"
        }
    for i = 1, #devices do
    s = otherdevices_lastupdate[devices[i]]
    year = string.sub(s, 1, 4)
    month = string.sub(s, 6, 7)
    day = string.sub(s, 9, 10)
    hour = string.sub(s, 12, 13)
    minutes = string.sub(s, 15, 16)
    seconds = string.sub(s, 18, 19)
    t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
    str = (devices[i] .. "LastUpdate")
    str = str:gsub("%s+", "")
    str = string.gsub(str, "%s+", "")
    _G[str] = (os.difftime (t1, t2))
end

-- Domoticz Configuration
username="USERNAME"
password="PASSWORD"
server="192.168.0.5"

commandArray = {}

-- Get Domoticz Uptime in Minutes
json = (loadfile "/root/domoticz/scripts/lua/JSON.lua")()
command='curl -s -k "https://'..username..':'..password..'@'..server..'/json.htm?type=command&param=getuptime"'
local handle = io.popen(command)
local result = handle:read("*a")
handle:close()
output = json:decode(result)
domoticzuptime = ((output.days * 1440) + (output.hours * 60) + (output.minutes))

-- Microwave kWh type: Aeotec ZW096 Smart Switch 6+
if (MicrowavekWhLastUpdate > 300 and domoticzuptime > 10) then
print("Microwave kWh has failed to update, re-progamming Z-Wave node...")
payload = '/json.htm?type=command&param=applyzwavenodeconfig&idx=28&valuelist=91_MjU%3D_92_NQ%3D%3D_101_MTI%3D_102_MA%3D%3D_103_MA%3D%3D_111_NA%3D%3D_112_NjAw_113_OTAw_254_MA%3D%3D_3_QWN0aXZlIE92ZXJsb2FkIFByb3RlY3Rpb24gKERlZmF1bHQp_20_TGFzdCBzdGF0dXMgKERlZmF1bHQp_21_UmVzZXJ2ZWQ%3D_80_Tm90aGluZyAoRGVmYXVsdCk%3D_81_V2hlbiB0aGUgc3RhdGUgb2YgdGhlIFN3aXRjaCBjaGFuZ2VzLCB0aGUgTEVEIHdpbGwgZm9sbG93IHRoZSBzdGF0dXMgKG9uL29mZikgb2YgaXRzIGxvYWQsIGJ1dCB0aGUgTEVEIHdpbGwgdHVybiBvZmYgYWZ0ZXIgNSBzZWNvbmRzLg%3D%3D_90_RmFsc2U%3D_200_QWVvbiBMYWJzIFN0YW5kYXJkIChEZWZhdWx0KQ%3D%3D_252_RGlzYWJsZQ%3D%3D_'
os.execute('curl -s -k "https://'..username..':'..password..'@'..server..''..payload..'"')
end

return commandArray

I've noticed many of my "Aeotec ZW096 Smart Switch 6"'s sometimes stop reporting power usage unless I restart or re-program them, hence my script above. :mrgreen:
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest