Dear All,
I would like to ask some help in case of check Samsung TV state check in Domoticz with LUA code.
First I have used this code to check the state of my TV set (with ping command):
Code: Select all
commandArray = {}
ping_success=os.execute('ping -c1 192.168.1.152')
if ping_success then
print("ping success")
commandArray['Nappali TV']='On'
else
print("ping fail")
commandArray['Nappali TV']='Off'
end
return commandArray
This code give a good status of my TV set, but if I want to register an event to the turn on function (ex.: e-mail sending), then it is not a good solution.
Because the above code change almost every second (when ping command run again) the state of the switch to ON state (so I got hundreds of mail to mail box).
So I have changed to the bellow code to avoid this, and registered an user variable for the ON state:
Code: Select all
commandArray = {}
ping_success=os.execute('ping -c1 192.168.1.152')
if ping_success and uservariables['TvStatus'] ~= 'On' then
print("TV Online")
commandArray['Variable:TvStatus']='On'
commandArray['Nappali TV']='On'
elseif not ping_success and uservariables['TvStatus'] ~= 'Off' then
print("TV Offline")
commandArray['Variable:TvStatus']='Off'
commandArray['Nappali TV']='Off'
end
return commandArray
My problem is that the above code working on the first turn on state, and then the off state, but after that the switch always show off state (and the the user variable stuck in ON state).
It looks like to me after the first on state the program change the user variable to "ON", and then when I turn off the TV, then the ping command fail, and LUA scrip give an error message, that the script was running more than 10 sec, and shut down.
So because the script shut down the user variable stay in "ON" condition, and even scrip restart the switch status won't change in the future.
Please can you check my code, and give me a good suggestion to solve this problem?!
Thank you for your support!