Page 1 of 1
Possible to restart a Plugin ?
Posted: Sunday 24 October 2021 16:51
by madpatrick
Hi,
Is it possibleto restart a plugin without restarting Domoticz.
The Somfy Plugin sometimes looses connection with the API site and give then a error that it is not able to login and stay this way.
Code: Select all
2021-10-24 16:30:25.632 Error: Somfy Tahoma: (Somfy Tahoma) Tahoma error must reconnect
2021-10-24 16:30:26.244 Error: Somfy Tahoma: (Somfy Tahoma) 'onMessage' failed 'KeyError'.
2021-10-24 16:30:26.244 Error: Somfy Tahoma: (Somfy Tahoma) ----> Line 283 in '/var/domoticz/plugins/domoticz_tahoma_blind/plugin.py', function onMessage
2021-10-24 16:30:26.244 Error: Somfy Tahoma: (Somfy Tahoma) ----> Line 82 in '/var/domoticz/plugins/domoticz_tahoma_blind/plugin.py', function onMessage
2021-10-24 16:30:26.245 Error: Somfy Tahoma: (Somfy Tahoma) 'onMessage' failed 'KeyError'.
By restarting(reloading) the plugin is working againg (make it in the Hardware page non-active/active)
https://github.com/nonolk/domoticz_tahoma_blind
If it is possible, can i do this in the script?
Re: Possible to restart a Plugin ?
Posted: Sunday 24 October 2021 17:55
by pipiche
Yes, it is possible, but it is a bit weird as the plugin is going to kill itself to restart.
You have to use the Domoticz JSON API:
https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s
/json.htm?type=command¶m=updatehardware
Re: Possible to restart a Plugin ?
Posted: Monday 25 October 2021 1:13
by waltervl
For a restart I use the update button. Just select the hardware and click on update ( without changing anything).
Re: Possible to restart a Plugin ?
Posted: Monday 25 October 2021 11:05
by madpatrick
Thnaks for the replies.
Is this possible to add this in the script ?
I'm a nono on Python, so any feedback will help
Re: Possible to restart a Plugin ?
Posted: Monday 25 October 2021 18:03
by waltervl
It is possible but needs some rework and an extra definition of the IP of your Domoticz installation.
But perhaps you can also enable the data timeout function in the hardware definition (menu Setup - Hardware)
If the plugin does not receive data during a defined time frame the plugin will be restarted by Domoticz.
Re: Possible to restart a Plugin ?
Posted: Tuesday 26 October 2021 20:43
by madpatrick
waltervl wrote: ↑Monday 25 October 2021 18:03
But perhaps you can also enable the data timeout function in the hardware definition (menu Setup - Hardware)
If the plugin does not receive data during a defined time frame the plugin will be restarted by Domoticz.
Thanks for the tip.
Unfortunately this does not the trick.
It restarts to often.
Code: Select all
2021-10-26 01:29:49.819 Error: Somfy Tahoma hardware (8) nothing received for more than 5 Minutes!....
2021-10-26 01:29:50.819 Error: Restarting: Somfy Tahoma
2021-10-26 01:34:58.071 Error: Somfy Tahoma hardware (8) nothing received for more than 5 Minutes!....
2021-10-26 01:34:59.072 Error: Restarting: Somfy Tahoma
2021-10-26 01:40:06.382 Error: Somfy Tahoma hardware (8) nothing received for more than 5 Minutes!....
2021-10-26 01:40:07.382 Error: Restarting: Somfy Tahoma
I think because it makes a connection to the API site when i click a button.
When there is an error it will come up and needs to restart.
Code: Select all
2021-10-26 10:02:43.051 Status: Somfy Tahoma: (Somfy Tahoma) Too much connections waiting before authenticating again
2021-10-26 10:02:53.070 Status: Somfy Tahoma: (Somfy Tahoma) Too much connections waiting before authenticating again
2021-10-26 10:03:03.088 Status: Somfy Tahoma: (Somfy Tahoma) Too much connections waiting before authenticating again
2021-10-26 10:03:13.056 Status: Somfy Tahoma: (Somfy Tahoma) Too much connections waiting before authenticating again
2021-10-26 10:03:23.075 Status: Somfy Tahoma: (Somfy Tahoma) Too much connections waiting before authenticating again
2021-10-26 10:03:33.093 Status: Somfy Tahoma: (Somfy Tahoma) Too much connections waiting before authenticating again
Re: Possible to restart a Plugin ?
Posted: Wednesday 27 October 2021 0:15
by waltervl
A timeout of 5 minutes is a little bit too fast in my opinion 30 or 60 minutes should be better.
Alternative road will be to find out why the error occurs , perhaps catch the error properly in Python so the plugin will not crash and needs to be restarted
Re: Possible to restart a Plugin ?
Posted: Sunday 31 October 2021 8:27
by madpatrick
waltervl wrote: ↑Wednesday 27 October 2021 0:15
A timeout of 5 minutes is a little bit too fast in my opinion 30 or 60 minutes should be better.
Alternative road will be to find out why the error occurs , perhaps catch the error properly in Python so the plugin will not crash and needs to be restarted
The problems occurs when i want to activate the comand and it's makes connection to the Somfy website.
Then it returns an error (like above).
After getting this error it want to restart the plugin.
Propably it connects not to the site regurarly so it doesn't matter how long the delay is. (I think)
In the sctipy is see 2 routines for errors
Code: Select all
elif ((Status == 401) or (Status == 400)):
strData = Data["Data"].decode("utf-8", "ignore")
Domoticz.Error("Tahoma error must reconnect")
self.logged_in = False
self.cookie = None
self.listenerId = None
if ("Too many" in strData):
Domoticz.Error("Too much connexions must wait")
self.heartbeat = True
return
if ("Bad credentials" in strData):
Domoticz.Error("Bad credentials please update credentials and restart plugin")
self.heartbeat = False
return
Could this be adjusted ?
Re: Possible to restart a Plugin ?
Posted: Wednesday 10 November 2021 15:24
by madpatrick
I think there is an other option
I've have a script in Dzventz which reads the log file for errors.
This script can detect a Somfy error so i can update the Hardware by Disable and then Enable ?
Code: Select all
local scriptVersion = 'Versie 1.01'
scriptVar = "-=# Domoticz ErrorLog #=-"
return
{
on = {
httpResponses = { scriptVar,},
timer = {"every 10 minutes"},
devices = {502},
},
logging = {
level = domoticz.LOG_INFO,
marker = scriptVar,
},
data = {
lastlogtime =
{
initial = 0
}
},
execute = function(dz, item)
local searchStr = 'Error: Somfy Tahoma' -- Change to reflect the messages you want to catch
local ignoreStrings = -- Enter all strings to be ignored in this table
{
'CheckAuthToken',
}
local function trueError(str)
for _, ignore in ipairs(ignoreStrings) do
if str:find(ignore) then return false end
end
return true
end
local function askDomoticzForLogLines()
local lastLogTime = dz.data.lastlogtime -- get time last logrequest
local logLevel = 4 -- loglevel (1=normal,2=Status,4=error,268435455=all
local jsonString = "/json.htm?type=command" .. "¶m=getlog" .. "&lastlogtime=" .. tostring(lastLogTime) .. "&loglevel=" .. tostring(logLevel)
dz.openURL(
{
url = dz.settings["Domoticz url"] .. jsonString,
callback = scriptVar
})
dz.data.lastlogtime = os.time() -- store current Time as seconds from epoch
end
local function findString()
if item.json.result then -- Only when there are errormessages in the log
local rt = item.json.result
for i = #rt, 1, -1 do -- traverse backwards to get latest violation first
local msg = rt[i].message
if msg:find('%s%s' .. searchStr) and trueError(msg) then return msg end
end
end
end
if item.isDevice or item.isTimer then
askDomoticzForLogLines() -- get the relevant loglines
elseif item.json then
--dz.log("Show ALL: \n" .. item.data,dz.LOG_INFO)
local line = findString()
if line then
dz.log("Log " .. searchStr .. " found! ",dz.LOG_INFO)
dz.openURL({url = 'http://192.168.1.234:9200/json.htm?type=command¶m=updatehardware&htype=94&name=Somfy%20Tahoma&enabled=false&idx=8&port=0&loglevel=7&Mode6=Normal&datatimeout=0&extra=tahomaIO&loglevel=268435455&username=xxxxxxxxx&password=xxxxxxxx3',
method = 'POST',}
)
dz.openURL({url = 'http://192.168.1.234:9200/json.htm?type=command¶m=updatehardware&htype=94&name=Somfy%20Tahoma&enabled=true&idx=8&port=0&loglevel=7&Mode6=Normal&datatimeout=0&extra=tahomaIO&loglevel=268435455&username=xxxxxxxxx&password=xxxxxxxx',
method = 'POST',}
)
dz.notify("Log " .. line .. " found! ",dz.PRIORITY_HIGH)
else
dz.log("No (new) occurrences of string " .. searchStr .. " in the domoticz log ",dz.LOG_INFO)
end
else
dz.log("Access problem to log. Data found: " .. item.data,dz.LOG_ERROR)
end
end
}
The problem now is that the to OpenURL commands are to quick after each other.
IS it possible to get a delay between them ?
Re: Possible to restart a Plugin ?
Posted: Saturday 13 November 2021 20:06
by JanJaap
All,
To my humble opinion restarting automatically a plugin is fighting symptoms rather then solving the root cause of the issue, which seems that connections are being opened. I've scanned quickly though the plugin and it looks like the author would be better of using the python requests library to handle the communication. You can add a time out to the API calls, build a retry and just throw a nicely handled error (rather then letting the app crash). Check my
Goodwe plugin for examples when needed (not sure it the author is reading here).
Re: Possible to restart a Plugin ?
Posted: Saturday 13 November 2021 20:19
by madpatrick
Hi
Unfortunately is the writter not supporting the plugin anymore.
So if somebody support on adjusting the plugin a lot of users will be happy
Re: Possible to restart a Plugin ?
Posted: Sunday 21 November 2021 20:14
by JanJaap
Hi guys,
I love to help out but I do not have any Somfy hardware so I can't test any changes. If one of you guys creates a branch and tells me how to signup somewhere then I can have a go at it. Hopefully that is then enough to get to basis stuff to work.
Re: Possible to restart a Plugin ?
Posted: Sunday 21 November 2021 21:50
by madpatrick
Hello JanJaap
Good to hear you want to help.
I can setup a branch on Github if needed.
The only issue could be the connection to Somfy.
You need to register with a Somfy box first as far as i know.
For testing i can give you access to my Somfy account, but this will activate my screens during testing

Re: Possible to restart a Plugin ?
Posted: Sunday 21 November 2021 22:09
by JanJaap
All right please set up the branch, I'll push some changes later this week. Will probably create some log files to capture the responses. Can you describe on your branch github page the setup process or at least the link for the somfy account? I'll see where I get with only an account and no device....
Re: Possible to restart a Plugin ?
Posted: Monday 22 November 2021 8:22
by madpatrick
Hello JanJaap,
I'll send you a PM
Re: Possible to restart a Plugin ?
Posted: Thursday 02 June 2022 11:48
by JanCeuleers
My hunch as to why the errors occur and the devices go unresponsive (which, by the way, is also happening to me in V1.0.9 of the plugin) is as follows:
I recently added 4 more devices to my Domoticz install. I already had a few Tuya devices active. The plugin's method of adding devices adds all devices found in the Tuya (or Smart Life, ...) account in Domoticz, including the ones that already existed. So the result is that each physical device has multiple entries in Domoticz's device table, and it can be hard to know which-ones are current.