Sync Home assistant and domoticz

Hello the communuty,
Soory im noob :frowning:

i try to synchronise state of the switch of domoticz. Here is my configuration :slight_smile:

 switch:
  - platform: command_line
    switches:
      nom_test:
        command_on: "/usr/bin/curl 'http://10.27.1.1:8855/json.htm?param=udevice&type=command&idx=115&nvalue=1'"
        command_off: "/usr/bin/curl 'http://10.27.1.1:8855/json.htm?param=udevice&type=command&idx=115&nvalue=0'"
        command_state: "/usr/bin/curl -X GET http://10.27.1.1:8855/json.htm?type=devices&rid=115"
        value_template: '{{ value_json.result.Status }}'
        friendly_name: test
```````````````````````````````````````````````````````````````
The result of my http comand_state : 
```````````````````````````````````````````````````````````````
{
	"ActTime" : 1595910719,
	"AstrTwilightEnd" : "19:16",
	"AstrTwilightStart" : "05:34",
	"CivTwilightEnd" : "18:22",
	"CivTwilightStart" : "06:28",
	"DayLength" : "11:08",
	"NautTwilightEnd" : "18:49",
	"NautTwilightStart" : "06:01",
	"ServerTime" : "2020-07-28 08:31:59",
	"SunAtSouth" : "12:25",
	"Sunrise" : "06:51",
	"Sunset" : "17:59",
	"app_version" : "2020.2",
	"result" : 
	[
		{
			"AddjMulti" : 1.0,
			"AddjMulti2" : 1.0,
			"AddjValue" : 0.0,
			"AddjValue2" : 0.0,
			"BatteryLevel" : 255,
			"CustomImage" : 0,
			"Data" : "On",
			"Description" : "",
			"DimmerType" : "none",
			"Favorite" : 0,
			"HardwareID" : 3,
			"HardwareName" : "Virtuel",
			"HardwareType" : "Dummy (Does nothing, use for virtual switches only)",
			"HardwareTypeVal" : 15,
			"HaveDimmer" : false,
			"HaveGroupCmd" : true,
			"HaveTimeout" : false,
			"ID" : "79",
			"Image" : "Light",
			"IsSubDevice" : false,
			"LastUpdate" : "2020-07-24 15:14:34",
			"Level" : 0,
			"LevelInt" : 0,
			"MaxDimLevel" : 0,
			"Name" : "test",
			"Notifications" : "false",
			"PlanID" : "0",
			"PlanIDs" : 
			[
				0
			],
			"Protected" : false,
			"ShowNotifications" : true,
			"SignalLevel" : "-",
			"Status" : "On",         <-- Seem to be here a solution
			"StrParam1" : "",
			"StrParam2" : "",
			"SubType" : "X10",
			"SwitchType" : "On/Off",
			"SwitchTypeVal" : 0,
			"Timers" : "false",
			"Type" : "Lighting 1",
			"TypeImg" : "lightbulb",
			"Unit" : 1,
			"Used" : 1,
			"UsedByCamera" : false,
			"XOffset" : "0",
			"YOffset" : "0",
			"idx" : "115"
		}
	],
	"status" : "OK",
	"title" : "Devices"
}
`````````````````````````````````````````````````````````
The On off command work perfectly. My problem is when i change value on domoticz Home assitant is not sync.

Is there any solution to sync with json put on when statut is on and off when statut is off?

I have seen pooling option car i make a request every 5 minutes to sync?

Thx a lot :)

I see it is an old question, but since I only recent started converting my stuff from Domoticz to Home Assistant, I found this solution to get the state for a switch updated:

switch
- platform: command_line
  switches:
    warm_water:
      command_on: '/usr/bin/curl "http://192.168.1.109:8080/json.htm?type=command&param=switchlight&idx=175&switchcmd=On"'
      command_off: '/usr/bin/curl "http://192.168.1.109:8080/json.htm?type=command&param=switchlight&idx=175&switchcmd=Off"'
      command_state: '/usr/bin/curl "http://192.168.1.109:8080/json.htm?type=devices&rid=175"'
      value_template: "{{ value_json.result[0].Status == 'On'}}"
      friendly_name: Warm Water Circulatie

I think the important part is the result[0], since the data is returned as a JSON array. Hopefully this will save some work for others.

1 Like