Update HaveTimeout field in switch device via json url using a bash script

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
averter
Posts: 45
Joined: Thursday 24 February 2022 8:32
Target OS: Linux
Domoticz version: 2024.4
Contact:

Update HaveTimeout field in switch device via json url using a bash script

Post by averter »

Background: I have developed a bash script (run via a domoticz switch) which will 1) turn on/off the gpio of a raspberry pi controlled irrigation system, and 2) if it fails to do so will keep trying a certain number of times, 3) after which it will send me an sms notification, display a log message in domoticz...and desirably...also flag/highlight the switch in domoticz.
The last part of highlighting the switch is where I am struggling the most. My current plan is to update the switch device via json, so that the "HaveTimeout" field is set to true instead of false. I believe that this would turn the switch red, which is ideal, but any other suggestions are welcome.

The info about the device is shown below

Code: Select all

curl -s 'http://192.168.88.155:8080/json.htm?type=command&param=getdevices&rid=45'
{
	"ActTime" : 1692389658,
	"AstrTwilightEnd" : "21:56",
	"AstrTwilightStart" : "05:16",
	"CivTwilightEnd" : "20:48",
	"CivTwilightStart" : "06:24",
	"DayLength" : "13:30",
	"NautTwilightEnd" : "21:21",
	"NautTwilightStart" : "05:51",
	"ServerTime" : "2023-08-18 21:14:18",
	"SunAtSouth" : "13:36",
	"Sunrise" : "06:51",
	"Sunset" : "20:21",
	"app_version" : "2023.2",
	"result" : 
	[
		{
			"AddjMulti" : 1.0,
			"AddjMulti2" : 1.0,
			"AddjValue" : 0.0,
			"AddjValue2" : 0.0,
			"BatteryLevel" : 255,
			"CustomImage" : 1,
			"Data" : "Off",
			"Description" : "",
			"DimmerType" : "none",
			"Favorite" : 0,
			"HardwareDisabled" : false,
			"HardwareID" : 8,
			"HardwareName" : "Pool",
			"HardwareType" : "Dummy (Does nothing, use for virtual switches only)",
			"HardwareTypeVal" : 15,
			"HaveDimmer" : true,
			"HaveGroupCmd" : true,
			"HaveTimeout" : false,
			"ID" : "0001407D",
			"Image" : "WallSocket",
			"IsSubDevice" : false,
			"LastUpdate" : "2023-08-18 19:22:04",
			"Level" : 0,
			"LevelInt" : 0,
			"MaxDimLevel" : 100,
			"Name" : "test switch",
			"Notifications" : "false",
			"PlanID" : "0",
			"PlanIDs" : 
			[
				0
			],
			"Protected" : false,
			"ShowNotifications" : true,
			"SignalLevel" : "-",
			"Status" : "Off",
			"StrParam1" : "",
			"StrParam2" : "",
			"SubType" : "Switch",
			"SwitchType" : "On/Off",
			"SwitchTypeVal" : 0,
			"Timers" : "false",
			"Type" : "Light/Switch",
			"TypeImg" : "lightbulb",
			"Unit" : 1,
			"Used" : 1,
			"UsedByCamera" : false,
			"XOffset" : "0",
			"YOffset" : "0",
			"idx" : "45"
		}
	],
	"status" : "OK",
	"title" : "Devices"
}
After reading the documentation there doesn't seem to be such option. I've tried using udevice, setused, setdevused parameters but nothing worked...so annoying.
User avatar
waltervl
Posts: 5396
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Update HaveTimeout field in switch device via json url using a bash script

Post by waltervl »

I don't know the answer to your question. But I have some other questions:
1. How do you check the gpio switch has switched from a bash script? Do you have an extra sensor somewhere that monitors this?
2. Why do you not use the gpio module of Domoticz or do you use a different RPI for this? In that case perhaps better buy a esp board, cheaper and easier to setup.with Domoticz environment.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
averter
Posts: 45
Joined: Thursday 24 February 2022 8:32
Target OS: Linux
Domoticz version: 2024.4
Contact:

Re: Update HaveTimeout field in switch device via json url using a bash script

Post by averter »

waltervl wrote: Saturday 19 August 2023 0:21 I don't know the answer to your question. But I have some other questions:
1. How do you check the gpio switch has switched from a bash script? Do you have an extra sensor somewhere that monitors this?
2. Why do you not use the gpio module of Domoticz or do you use a different RPI for this? In that case perhaps better buy a esp board, cheaper and easier to setup.with Domoticz environment.
Thanks waltervl. To answer your questions:
1. The problem is more fundamental than just checking if the gpio switch has been switched on/off; the network in my home has several APs and one range extender and connectivity issues, between the master raspberry which hosts domoticz and all the remaining ones, are somewhat common. Therefore the bash script looks at the exit code of an ssh command which toggles the gpio pin; if it is =0 all is fine, otherwise it enters the "red zone" while loop which does all that I have mentioned before. In particular, a 255 code indicates that something went very wrong with the ssh command (most likely a connectivity issue). Happy to share it if anyone is interested.
2. Yes, I use a different RPI for this. There's a few more doing the same thing actually, hence why it's useful to highlight the switch which has failed visually (to spot it straightaway in the middle of all the other switches :) ). Thanks for the suggestion of an esp board. If it had such failsafe switch option when setup via domoticz then perhaps...
averter
Posts: 45
Joined: Thursday 24 February 2022 8:32
Target OS: Linux
Domoticz version: 2024.4
Contact:

Re: Update HaveTimeout field in switch device via json url using a bash script

Post by averter »

I believe that the key lies in this section https://www.domoticz.com/wiki/Domoticz_ ... .2Fsensors
and I would expect that this code would work

Code: Select all

curl -s 'http://192.168.88.155:8080/json.htm?type=command&param=setused&used=true&HaveTimeout=true&idx=45'
but it does not...I'll keep trying other things
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests