Asking help to debug a script checking who=5

Hello, I finally moved from 2.5 to latest 3.2.0, using the official openwebnet binding. I have two gateways installed, the MHS1 for automation/lights, ecc, fully woking as expect, and one unofficial LN4890 used by domoticz and still connected
I’m trying to control a 3486 alarm through the LN4890 because MHS1 filters who=5 messages from network to bus, and I achieved to use a set of scripts downloaded from https://github.com/francesco-re-1107/openwebnet-alarm and adapted to actual syntax of exec binding. They work quite well to engage/disengage alarm via AUX commands, but one of scripts fails to check the actual status of alarm.
It is very simple:

from OpenWebNet import OpenWebNet

server = OpenWebNet(“192.168.1.50”,“20000”,“12345”)
res = server.stato_allarme()

#check result
if res == “58*##”: #alarm is enabled
print “1”
if res == “59*##”: #alarm is disabled
print “0”
if res == “”:
print “N”

I added the last if because most times the scripts does not receive all the message from bus, so it does not return 0 or 1 (here 3 different results fom execution with output of the received message and the script return code):

root@mhw:/usr/local/src/openwebnet-alarm-master # /usr/bin/python /usr/local/src/openwebnet-alarm-master/fm_status.py
(‘message’, ‘51*##59*##55*##’)
[‘51*##’, ‘59*##’, ‘55*##’, ‘’]
51*##59*##55*##
0

root@mhw:/usr/local/src/openwebnet-alarm-master # /usr/bin/python /usr/local/src/openwebnet-alarm-master/fm_status.py
(‘message’, ‘51*##59*##55*##57*##511*#1##511*#2##511*#3##’)
[‘51*##’, ‘59*##’, ‘55*##’, ‘57*##’, ‘511*#1##’, ‘511*#2##’, ‘511*#3##’, ‘’]
51*##59*##55*##57*##511*#1##511*#2##511*#3##
0

root@mhw:/usr/local/src/openwebnet-alarm-master # /usr/bin/python /usr/local/src/openwebnet-alarm-master/fm_status.py
(‘message’, ‘51*##’)
[‘51*##’, ‘’]
51*##
N

Naturally this problem causes the state of the item continously changing and a difficult managing:
2021-09-19 12:23:16.305 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Stato_allarme’ changed from 0 to N
2021-09-19 12:23:32.573 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Stato_allarme’ changed from N to 0
2021-09-19 12:23:59.695 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Stato_allarme’ changed from 0 to N
2021-09-19 12:24:05.208 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Stato_allarme’ changed from N to 0

I do not know python, is there someone good enough to help me?
TY in advance

What are you saying, you don’t want your Item updated unless code 58 or 59 is present? May we see your channel config?

I have no config. The who=5 is unsupported from actual openwebnet binding, so I try to use a script directly accessing the gateway to control the 3486 unit via AUX.
The AUX command work perfectly: when I want to engage the alarm have such a rule:
rule “Alarm state changed from 0 to 1”
when
Item Stato_allarme changed from 0 to 1
then
Allarme.sendCommand(ON)
end
//
Same for disengage, but the script to check the status of the alarm does not always return 0 or 1, because the own message coming back is not well decoded from python library. Most times the script returns nothing, so I modified it to return N when the message is not correct, but this is not good because the status always change from 0 to N or from 1 to N and back from N to 0 or 1

Okay.
And you showed us an Item Stato_allarme that tracks that, getting updated by some mysterious means that you did not configure.

But you don’t want Stato_allarme to get state N? You’d need to find out the mysterious update method and have it do nothing in the N case.

That item is configured as an exec:command in things and items files:

Thing exec:command:alarm_state [command="/usr/bin/python /usr/local/src/openwebnet-alarm-master/alarm_status.py", interval=5, timeout=1, autorun=true ]

String Stato_allarme {channel=“exec:command:alarm_state:output”}

The state N is only a trick. When you send a “#50##” to a gateway it passes the open command to 3486 who MUST answer following the own protocol, and the script MUST answer 0 or 1 after analizing the own answer from 3486 (0=disengaged, 1=engaged, the alarm cannot have other states if it’s active). But if the script fails to decode the own answer, it simply exit without returning neither 0 or 1 so I force the N to debug if the answer is null. But I’m not a programmer and the python script, that I downloaded from https://github.com/francesco-re-1107/openwebnet-alarm is quite difficult for me to debug. That’s why I ask help from a python programmer.
This solution could answer many guy that still have the 3486 and cannot manage it