Page 1 of 1

restart hardware service from script

Posted: Friday 13 December 2019 22:00
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...

Re: restart hardware service from script  [Solved]

Posted: Saturday 14 December 2019 1:14
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
}

Re: restart hardware service from script

Posted: Thursday 19 December 2019 20:49
by franzelare
thanks!
i put this in a script, so will see at the next failure if it works

Re: restart hardware service from script

Posted: Friday 02 July 2021 1:18
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.