Binding to Domoticz

How to integrate SPC Web Gateway with different Home Automation Systems
Rena
Posts: 14
Joined: Sun 13 Sep 2015, 19:00

Re: Binding to Domoticz

Post by Rena » Mon 07 Dec 2015, 17:14

My config.json looks like this. HC2-user is the same as Domoticz user? Anything that looks wrong?

{
"spc_gw_host":"localhost",
"spc_gw_port":"8088",
"spc_ws_user":"pi",
"spc_ws_password":"rena4747",
"spc_get_user":"pi",
"spc_get_password":"rena4747",
"hc2_user":"<rena>",
"hc2_password":"<rena4747>",
"domo_host":"<192.168.1.7>"
"domo_port":"8080", // Default Port 8080
"naming":"0" // 0 for numbering, 1 for naming
}

gol
Webbplatsadministratör
Posts: 80
Joined: Sun 01 Jun 2014, 19:38

Re: Binding to Domoticz

Post by gol » Tue 08 Dec 2015, 08:19

Rena wrote:My config.json looks like this. HC2-user is the same as Domoticz user? Anything that looks wrong?

{
"spc_gw_host":"localhost",
"spc_gw_port":"8088",
"spc_ws_user":"pi",
"spc_ws_password":"rena4747",
"spc_get_user":"pi",
"spc_get_password":"rena4747",
"hc2_user":"<rena>",
"hc2_password":"<rena4747>",
"domo_host":"<192.168.1.7>"
"domo_port":"8080", // Default Port 8080
"naming":"0" // 0 for numbering, 1 for naming
}
Comments are not allowed in JSON, and you should skip the <> characters and there is a missing comma in "domo_host"-line. Try something like this:
{
"spc_gw_host":"localhost",
"spc_gw_port":"8088",
"spc_ws_user":"pi",
"spc_ws_password":"rena4747",
"spc_get_user":"pi",
"spc_get_password":"rena4747",
"hc2_user":"rena",
"hc2_password":"rena4747",
"domo_host":"192.168.1.7",
"domo_port":"8080",
"naming":"0"
}

Rena
Posts: 14
Joined: Sun 13 Sep 2015, 19:00

Re: Binding to Domoticz

Post by Rena » Tue 08 Dec 2015, 17:35

gol wrote:
Rena wrote:My config.json looks like this. HC2-user is the same as Domoticz user? Anything that looks wrong?

{
"spc_gw_host":"localhost",
"spc_gw_port":"8088",
"spc_ws_user":"pi",
"spc_ws_password":"rena4747",
"spc_get_user":"pi",
"spc_get_password":"rena4747",
"hc2_user":"<rena>",
"hc2_password":"<rena4747>",
"domo_host":"<192.168.1.7>"
"domo_port":"8080", // Default Port 8080
"naming":"0" // 0 for numbering, 1 for naming
}
Comments are not allowed in JSON, and you should skip the <> characters and there is a missing comma in "domo_host"-line. Try something like this:
{
"spc_gw_host":"localhost",
"spc_gw_port":"8088",
"spc_ws_user":"pi",
"spc_ws_password":"rena4747",
"spc_get_user":"pi",
"spc_get_password":"rena4747",
"hc2_user":"rena",
"hc2_password":"rena4747",
"domo_host":"192.168.1.7",
"domo_port":"8080",
"naming":"0"
}
Now it works better, also changed from localhost to IP-address.

How to do if I want to add status of a PIR from the SPC?

fergalom
Posts: 15
Joined: Fri 11 Sep 2015, 09:16

Re: Binding to Domoticz

Post by fergalom » Tue 08 Dec 2015, 18:58

ok so you now have all your spc alarm statuses in Domoticz as variables and can see them on the user variables page.

If you want to see them on the dashboard, you will need to setup dummy switches and dummy pir switches in domoticz and use a lua script to update them based on the user variable status.

In your domoticz/scripts/lua directory, place a script named script_variable_spc.lua
This is my script, you will need to modify this to suit you system.

Code: Select all

commandArray = {}
logging = true
if (uservariablechanged['G_SPC_AREA_House'] == 'unset') then
   commandArray['House Alarm Set/Unset']='Off'
elseif (uservariablechanged['G_SPC_AREA_House'] == 'set') then
   commandArray['House Alarm Set/Unset']='On'
end
if (uservariablechanged['G_SPC_AREA_Shed'] == 'unset') then
   commandArray['Shed Alarm Set/Unset']='Off'
elseif (uservariablechanged['G_SPC_AREA_Shed'] == 'set') then
   commandArray['Shed Alarm Set/Unset']='On'
end
if (uservariablechanged['G_SPC_ZONE_INPUT_PIR_Front_Door'] == 'open') then
   commandArray['Hall Motion']='On'
   print('Hall PIR Motion')
else commandArray['Hall Motion']='Off'
end
if (uservariablechanged['G_SPC_ZONE_INPUT_Shed_PIR'] == 'open') then
   commandArray['Shed Motion']='On'
   print('Shed PIR Motion')
else commandArray['Shed Motion']='Off'
end
if (uservariablechanged['G_SPC_ZONE_INPUT_Kitchen_PIR'] == 'open') then
   commandArray['Kitchen Motion']='On'
   print('Kitchen PIR Motion')
else commandArray['Kitchen Motion']='Off'
end

if (uservariablechanged['G_SPC_ZONE_INPUT_Front_Door'] == 'open' and  otherdevices['Front Door']=='Closed') then
   commandArray['UpdateDevice']='122|1|Open'
   print('Front Door Open')
elseif (uservariablechanged['G_SPC_ZONE_INPUT_Front_Door'] == 'closed' and  otherdevices['Front Door']=='Open') then
   commandArray['UpdateDevice']='122|0|Closed'
   print('Front Door Closed')
end

if (uservariablechanged['G_SPC_ZONE_INPUT_Shed_Door_MC'] == 'open' and  otherdevices['Shed Door']=='Closed') then
   commandArray['UpdateDevice']='109|1|Open'
   print('Shed Door Open')
elseif (uservariablechanged['G_SPC_ZONE_INPUT_Shed_Door_MC'] == 'closed' and  otherdevices['Shed Door']=='Open') then
   commandArray['UpdateDevice']='109|0|Closed'
   print('Shed Door Closed')
end

if (uservariablechanged['G_SPC_ZONE_INPUT_DN_Windows_B'] == 'open' and  otherdevices['Back Door']=='Closed') then
   commandArray['UpdateDevice']='120|1|Open'
   print('Back Door Open')
elseif (uservariablechanged['G_SPC_ZONE_INPUT_DN_Windows_B'] == 'closed' and  otherdevices['Back Door']=='Open') then
   commandArray['UpdateDevice']='120|0|Closed'
   print('Back Door Closed')
end

return commandArray

Rena
Posts: 14
Joined: Sun 13 Sep 2015, 19:00

Re: Binding to Domoticz

Post by Rena » Wed 09 Dec 2015, 08:32

fergalom wrote:ok so you now have all your spc alarm statuses in Domoticz as variables and can see them on the user variables page.

If you want to see them on the dashboard, you will need to setup dummy switches and dummy pir switches in domoticz and use a lua script to update them based on the user variable status.

In your domoticz/scripts/lua directory, place a script named script_variable_spc.lua
This is my script, you will need to modify this to suit you system.

Code: Select all

commandArray = {}
logging = true
if (uservariablechanged['G_SPC_AREA_House'] == 'unset') then
   commandArray['House Alarm Set/Unset']='Off'
elseif (uservariablechanged['G_SPC_AREA_House'] == 'set') then
   commandArray['House Alarm Set/Unset']='On'
end
if (uservariablechanged['G_SPC_AREA_Shed'] == 'unset') then
   commandArray['Shed Alarm Set/Unset']='Off'
elseif (uservariablechanged['G_SPC_AREA_Shed'] == 'set') then
   commandArray['Shed Alarm Set/Unset']='On'
end
if (uservariablechanged['G_SPC_ZONE_INPUT_PIR_Front_Door'] == 'open') then
   commandArray['Hall Motion']='On'
   print('Hall PIR Motion')
else commandArray['Hall Motion']='Off'
end
if (uservariablechanged['G_SPC_ZONE_INPUT_Shed_PIR'] == 'open') then
   commandArray['Shed Motion']='On'
   print('Shed PIR Motion')
else commandArray['Shed Motion']='Off'
end
if (uservariablechanged['G_SPC_ZONE_INPUT_Kitchen_PIR'] == 'open') then
   commandArray['Kitchen Motion']='On'
   print('Kitchen PIR Motion')
else commandArray['Kitchen Motion']='Off'
end

if (uservariablechanged['G_SPC_ZONE_INPUT_Front_Door'] == 'open' and  otherdevices['Front Door']=='Closed') then
   commandArray['UpdateDevice']='122|1|Open'
   print('Front Door Open')
elseif (uservariablechanged['G_SPC_ZONE_INPUT_Front_Door'] == 'closed' and  otherdevices['Front Door']=='Open') then
   commandArray['UpdateDevice']='122|0|Closed'
   print('Front Door Closed')
end

if (uservariablechanged['G_SPC_ZONE_INPUT_Shed_Door_MC'] == 'open' and  otherdevices['Shed Door']=='Closed') then
   commandArray['UpdateDevice']='109|1|Open'
   print('Shed Door Open')
elseif (uservariablechanged['G_SPC_ZONE_INPUT_Shed_Door_MC'] == 'closed' and  otherdevices['Shed Door']=='Open') then
   commandArray['UpdateDevice']='109|0|Closed'
   print('Shed Door Closed')
end

if (uservariablechanged['G_SPC_ZONE_INPUT_DN_Windows_B'] == 'open' and  otherdevices['Back Door']=='Closed') then
   commandArray['UpdateDevice']='120|1|Open'
   print('Back Door Open')
elseif (uservariablechanged['G_SPC_ZONE_INPUT_DN_Windows_B'] == 'closed' and  otherdevices['Back Door']=='Open') then
   commandArray['UpdateDevice']='120|0|Closed'
   print('Back Door Closed')
end

return commandArray
Yes - now I see them under user variables.

I will try to set up a lua-script.

Thansk!

Rena
Posts: 14
Joined: Sun 13 Sep 2015, 19:00

Re: Binding to Domoticz

Post by Rena » Sun 13 Dec 2015, 17:44

I have made a Lua-script according to the example. At the moment I´m only interested if the alarm is ON or OFF so I can trigger a away-scenario.
Does the script look OK?


commandArray = {}
logging = true
if (uservariablechanged['G_SPC_AREA_MODE_1'] == 'unset') then
commandArray['House Alarm Set/Unset']='Off'
elseif (uservariablechanged['G_SPC_AREA_MODE_1'] == 'set') then
commandArray['House Alarm Set/Unset']='On'
end

return commandArray


I don´t really understand how to add the alarmstatus as a dummy-switch? Can anyone please try to show an example?

Rena
Posts: 14
Joined: Sun 13 Sep 2015, 19:00

Re: Binding to Domoticz

Post by Rena » Thu 14 Jan 2016, 20:07

Come on, help needed!

Rena
Posts: 14
Joined: Sun 13 Sep 2015, 19:00

Re: Binding to Domoticz

Post by Rena » Sat 16 Jan 2016, 18:26

Now I have figured out how to solve it. Next problem. I need something that start up the binding on reboot and most important of all, runs in the background.

As soons as I have started the binding and shut down Putty. It stops working. How to solve this?

mtak
Posts: 6
Joined: Thu 01 Sep 2016, 17:10

Re: Binding to Domoticz

Post by mtak » Thu 01 Sep 2016, 18:00

Hi,

I'm, trying to get this to work but unfortunally i get the below result (look at the first attempt below)

It looks like the binding works with the the spc gateway but it fails with domoticz.

In the node-spc-domticz-bindings.js i've found this
/*auth: config.hc2_user + ':' + config.hc2_password + '@',*/
in two places.
If I remove the comments I instead get result as in the second attempt below.
(the lines now looks like: auth: config.hc2_user + ':' + config.hc2_password + '@',)

I'm quite convinced that i've put the correct user and password in the config file.

I'm running domoticz 3.4834

Any suggestion?

Best Regards
Mattias

-----------------------------------------------------------------------------
First attempt
-----------------------------------------------------------------------------


pi@pih:~/node-spc-domoticz-binding$ ./node-spc-domoticz-binding.js
SPC WebSocket client connected
{ area:
[ { id: '1',
name: 'Boyta',
mode: '0',
last_set_time: '1472625780',
last_set_user_id: '5',
last_set_user_name: 'Vänerblick',
last_unset_time: '1472650562',
last_unset_user_id: '5',
last_unset_user_name: 'Vänerblick' },
{ id: '2',
name: 'Garage',
mode: '0',
last_set_time: '1472485130',
last_set_user_id: '9999',
last_set_user_name: 'Engineer',
last_unset_time: '1472485136',
last_unset_user_id: '9999',
last_unset_user_name: 'Engineer',
last_alarm: '1472485136' },
{ id: '3', name: 'Utomhus', mode: '0' } ] }
unset
unset
unset
{ status: 'success',
data: { area: [ [Object], [Object], [Object] ] } }
{ status: 'success',
data:
{ zone:
[ [Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object] ] } }
<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
Failed to parse reply, expected JSON
<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
Failed to parse reply, expected JSON
<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
Failed to parse reply, expected JSON
<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
Failed to parse reply, expected JSON
<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
Failed to parse reply, expected JSON
<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
Failed to parse reply, expected JSON
<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
Failed to parse reply, expected JSON
<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
Failed to parse reply, expected JSON
<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
Failed to parse reply, expected JSON
<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>



-----------------------------------------------------------------------------
Second attempt with auth
-----------------------------------------------------------------------------


i@pih:~/node-spc-domoticz-binding$ ./node-spc-domoticz-binding.js
SPC WebSocket client connected
{ area:
[ { id: '1',
name: 'Boyta',
mode: '0',
last_set_time: '1472625780',
last_set_user_id: '5',
last_set_user_name: 'Vänerblick',
last_unset_time: '1472650562',
last_unset_user_id: '5',
last_unset_user_name: 'Vänerblick' },
{ id: '2',
name: 'Garage',
mode: '0',
last_set_time: '1472485130',
last_set_user_id: '9999',
last_set_user_name: 'Engineer',
last_unset_time: '1472485136',
last_unset_user_id: '9999',
last_unset_user_name: 'Engineer',
last_alarm: '1472485136' },
{ id: '3', name: 'Utomhus', mode: '0' } ] }
unset
unset
unset
{ status: 'success',
data: { area: [ [Object], [Object], [Object] ] } }
{ status: 'success',
data:
{ zone:
[ [Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object] ] } }
<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
Failed to parse reply, expected JSON
<html><head><title>Service Unavailable</title></head><body><h1>503 Service Unavailable</h1></body></html>
Failed to parse reply, expected JSON
<html><head><title>Service Unavailable</title></head><body><h1>503 Service Unavailable</h1></body></html>
Failed to parse reply, expected JSON
<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
Failed to parse reply, expected JSON
<html><head><title>Service Unavailable</title></head><body><h1>503 Service Unavailable</h1></body></html>
Failed to parse reply, expected JSON
<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
Failed to parse reply, expected JSON

-----------------------------------------------------------------------------------------------------------

mtak
Posts: 6
Joined: Thu 01 Sep 2016, 17:10

Re: Binding to Domoticz

Post by mtak » Tue 06 Sep 2016, 19:59

Hi,

Instead of using this Binding to Domoticz i'm now using the MQTT binding to connect to Domoticz and so far everything seems to work fine.

Regards
Mattias

Post Reply