restart hardware service from script  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
franzelare
Posts: 141
Joined: Thursday 19 February 2015 21:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

restart hardware service from script

Post by franzelare »

i was wondering if it is possible to restart a hardware service through dzvents?
my evo home heating control system web api sometimes stops working, when i restart the service is works fine again.
i know how to detect error strings using dzvents but like to be able to restart a service

2019-12-13 21:59:32.005 Status: (Evo Home) Worker stopped...
2019-12-13 21:59:32.006 Status: (Evo Home) Worker started...
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: restart hardware service from script  [Solved]

Post by waaren »

franzelare wrote: Friday 13 December 2019 22:00 i was wondering if it is possible to restart a hardware service through dzvents?

2019-12-13 21:59:32.005 Status: (Evo Home) Worker stopped...
2019-12-13 21:59:32.006 Status: (Evo Home) Worker started...
It is possible but not straight forward.

Code: Select all

return {
    on = {
        devices = {
            'evoTrigger'
        }
    },
    
    logging = 
    { 
        level = domoticz.LOG_DEBUG
    },
    
    execute = function(domoticz, device)
        _G.logMarker =  _G.moduleLabel
        
        local function evohome(action, delay)
    
            if action == 'restart' then 
                evohome('disable')
                evohome('enable', 3)
            end
        
            if not(dz) then dz = domoticz end
        
            local username = 'your userid' -- change
            local password = 'your password' -- change
            local hardwareName = 'Evohome' -- change 
            local hardwareIDX = xx  -- change

            local action = ( ( action == 'enable' and 'true' ) or 'false')

            local url = 
                 dz.settings['Domoticz url'] .. '/json.htm?type=command&param=updatehardware&htype=75' ..
                '&username=' .. dz.utils.urlEncode(username) ..
                '&password=' .. dz.utils.urlEncode(password) ..
                '&name=' .. dz.utils.urlEncode(hardwareName) ..
                '&idx=' .. tostring(hardwareIDX) ..
                '&enabled=' .. tostring(action) 

            dz.openURL(url).afterSec(delay or 0)  
        end

        -- call function with one of
            -- evohome('enable') -- or
            --  evohome('disable') -- or
            evohome('restart')
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
franzelare
Posts: 141
Joined: Thursday 19 February 2015 21:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: restart hardware service from script

Post by franzelare »

thanks!
i put this in a script, so will see at the next failure if it works
Alain
Posts: 166
Joined: Sunday 26 April 2020 5:27
Target OS: Linux
Domoticz version: 2022.1
Location: Netherlands
Contact:

Re: restart hardware service from script

Post by Alain »

waaren wrote: Saturday 14 December 2019 1:14
franzelare wrote: Friday 13 December 2019 22:00 i was wondering if it is possible to restart a hardware service through dzvents?

2019-12-13 21:59:32.005 Status: (Evo Home) Worker stopped...
2019-12-13 21:59:32.006 Status: (Evo Home) Worker started...
It is possible but not straight forward.

Code: Select all

return {
    on = {
        devices = {
            'evoTrigger'
        }
    },
    
    logging = 
    { 
        level = domoticz.LOG_DEBUG
    },
    
    execute = function(domoticz, device)
        _G.logMarker =  _G.moduleLabel
        
        local function evohome(action, delay)
    
            if action == 'restart' then 
                evohome('disable')
                evohome('enable', 3)
            end
        
            if not(dz) then dz = domoticz end
        
            local username = 'your userid' -- change
            local password = 'your password' -- change
            local hardwareName = 'Evohome' -- change 
            local hardwareIDX = xx  -- change

            local action = ( ( action == 'enable' and 'true' ) or 'false')

            local url = 
                 dz.settings['Domoticz url'] .. '/json.htm?type=command&param=updatehardware&htype=75' ..
                '&username=' .. dz.utils.urlEncode(username) ..
                '&password=' .. dz.utils.urlEncode(password) ..
                '&name=' .. dz.utils.urlEncode(hardwareName) ..
                '&idx=' .. tostring(hardwareIDX) ..
                '&enabled=' .. tostring(action) 

            dz.openURL(url).afterSec(delay or 0)  
        end

        -- call function with one of
            -- evohome('enable') -- or
            --  evohome('disable') -- or
            evohome('restart')
    end
}
I am running the ModbusRead and ModbusWrite plugins, but am having a problem with connection errors. The errors arise from the plugin sending a request to the Modbus device from different hardware devices. I have to create a new hardware device for every modbus address and I currently have 21 of them. in the plugin you can set the pollrate and I set them differently for each device, however, after a while, some will send a request to the same modbus device at the same time and it causes communication errors because the modbus device can't handle the multiple requests at the same time. The way to keep these errors to a minimum would be to have a script running that will automatically restart the plugin if a log message with the text "Modbus error decoding or received no data". I'm not very familiar with dzvents, so how would I go about modifying the above script?

I currently restart Domoticz twice a day via a crontab, but that's still not sufficient. More effective would be to restart the hardware device that's throwing the errors as that resets its polling time and gets it out of sync with another device.
Attachments
Hardware devices
Hardware devices
hardware.jpg (180.7 KiB) Viewed 1083 times
Hue | Zigbee2Mqtt | MQTT | P1 | Xiaomi | RFXCom | Modbus | Qlima | Solaredge
TP-Link | Plugwise | Thermosmart | Node-Red | Grafana | Master and 5 remote servers
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest