domoticz / Reacticz

Reacticz dashboard
Apache License 2.0
34 stars 15 forks source link

Add Door Lock Support? #20

Closed sfeakes closed 6 years ago

sfeakes commented 6 years ago

I noticed that my Door Locks were not supported, but door contacts are. After a quick look at code and Domoticz, is seems that if you make a small change to DeviceWidget.js you could at least display the status of the door lock, even though you couldn't control it.

Around Line 65, change

case 'Contact' :
case 'Door Contact' :
        return <ContactWidget label={device.name} value={device.nvalue}

To

case 'Contact' :
case 'Door Contact' :
case 'Door Lock' :
        return <ContactWidget label={device.name} value={device.nvalue}
t0mg commented 6 years ago

Wow, door locks on Domoticz? I hope your system is secure :) I'm assuming both your MQTT broker and Domoticz server are using SSL and passwords here.

What you propose might work but if these devices can be controlled, this is not the way to go. This code is for sensor-type devices, simply reporting a measurement and I'm assuming that these locks should probably behave like on/off switches instead. What does it look like on the Domoticz dashboard? Also, could you share the debug data?

sfeakes commented 6 years ago

Yup, there is no need to worry about security...:)

I was just looking for a quick way to get status, but fully functioning is just as good. Door locks work exactly the same in Domoticz as light switch, although the string status are (or can be different), depending on the lock, the messages sent to the lock itself is encrypted. (but that won't effect the MQTT message from Reacticz to Domoticz). Simply sending "switch on" to domoticz/in, i.e. JSON {"idx":105,"nvalue":1,"svalue":""} where 105 is the IDX of the lock would close the door / lock the lock.

One door lock is a ZWave schlage unit off the shelf hardware, the other 3 are garage door units with custom hardware. The 3 I designed have a safety in the hardware where they can only be closed (not opened) from the network interface. (But that won't effect this change to Reacticz)

In Domoticz it's simply a picture of a door closed (with padlock), or door open. Create a virtual door lock and you'll see.

What debug data would you like?

Here is the virtual door lock JSON data.

{
   "ActTime" : 1513785885,
   "ServerTime" : "2017-12-20 10:04:45",
   "Sunrise" : "07:15",
   "Sunset" : "17:24",
   "result" : [
      {
         "AddjMulti" : 1.0,
         "AddjMulti2" : 1.0,
         "AddjValue" : 0.0,
         "AddjValue2" : 0.0,
         "BatteryLevel" : 255,
         "CustomImage" : 0,
         "Data" : "Locked",
         "Description" : "",
         "Favorite" : 1,
         "HardwareID" : 2,
         "HardwareName" : "Virtual Sensors",
         "HardwareType" : "Dummy (Does nothing, use for virtual switches only)",
         "HardwareTypeVal" : 15,
         "HaveDimmer" : true,
         "HaveGroupCmd" : true,
         "HaveTimeout" : false,
         "ID" : "000140AF",
         "Image" : "Light",
         "InternalState" : "Locked",
         "IsSubDevice" : false,
         "LastUpdate" : "2017-12-20 10:04:38",
         "Level" : 0,
         "LevelInt" : 0,
         "MaxDimLevel" : 100,
         "Name" : "Garage Door Front Double",
         "Notifications" : "false",
         "PlanID" : "0",
         "PlanIDs" : [ 0 ],
         "Protected" : false,
         "ShowNotifications" : true,
         "SignalLevel" : "-",
         "Status" : "Locked",
         "StrParam1" : "",
         "StrParam2" : "",
         "SubType" : "Switch",
         "SwitchType" : "Door Lock",
         "SwitchTypeVal" : 19,
         "Timers" : "false",
         "Type" : "Light/Switch",
         "TypeImg" : "door",
         "Unit" : 1,
         "Used" : 1,
         "UsedByCamera" : false,
         "XOffset" : "0",
         "YOffset" : "0",
         "idx" : "95"
      }
   ],
   "status" : "OK",
   "title" : "Devices"
}

This is the ZWave unit

{
   "ActTime" : 1513794458,
   "ServerTime" : "2017-12-20 12:27:38",
   "Sunrise" : "07:15",
   "Sunset" : "17:24",
   "result" : [
      {
         "AddjMulti" : 1.0,
         "AddjMulti2" : 1.0,
         "AddjValue" : 0.0,
         "AddjValue2" : 0.0,
         "BatteryLevel" : 97,
         "CustomImage" : 0,
         "Data" : "Locked",
         "Description" : "",
         "Favorite" : 1,
         "HardwareID" : 10,
         "HardwareName" : "Z-Stick",
         "HardwareType" : "OpenZWave USB",
         "HardwareTypeVal" : 21,
         "HaveDimmer" : true,
         "HaveGroupCmd" : true,
         "HaveTimeout" : false,
         "ID" : "00000C01",
         "Image" : "Light",
         "InternalState" : "Locked",
         "IsSubDevice" : false,
         "LastUpdate" : "2017-12-20 10:18:27",
         "Level" : 255,
         "LevelInt" : 255,
         "MaxDimLevel" : 100,
         "Name" : "Back Door Lock",
         "Notifications" : "false",
         "PlanID" : "2",
         "PlanIDs" : [ 2 ],
         "Protected" : false,
         "ShowNotifications" : true,
         "SignalLevel" : "-",
         "Status" : "Locked",
         "StrParam1" : "",
         "StrParam2" : "",
         "SubType" : "Switch",
         "SwitchType" : "Door Lock",
         "SwitchTypeVal" : 19,
         "Timers" : "false",
         "Type" : "Light/Switch",
         "TypeImg" : "door",
         "Unit" : 1,
         "Used" : 1,
         "UsedByCamera" : false,
         "XOffset" : "0",
         "YOffset" : "0",
         "idx" : "64"
      }
   ],
   "status" : "OK",
   "title" : "Devices"
}
t0mg commented 6 years ago

By debug I meant whatever json is displayed in the "unsupported device" widgets that should show up on your Reacticz dashboard at the moment.

According to your explanations, it should be trivial to reuse the switch type widget here. But I feel like it should look different from a standard switch as we don't want a lock to be mistaken for a simple light. I'll give it a shot with a virtual device.

t0mg commented 6 years ago

Ok, I've extended the standard on/off switch to support locks and display a status icon. Here's what it looks like:

locked: lock closed

unlocked: lock open

What do you think? Part of me would expect the open status to be the bright one that stands out more, however this would not be consistent with the way we reflect "on" states in reacticz, since the on state is the locked state...

sfeakes commented 6 years ago

I think it looks great. But, you are right about the colors, and it is also inverse of the current Reacticz door contact. (Where grey is closed and Yellow is open).

In the software I've written for other management utilities, I've had to inverse the state depending on if it's a "contact" or a "lock".

Here are the 3 unsupported ones I have. (This door is a virtual door currently unlocked/open)

{"Battery":255,"RSSI":12,"description":"","dtype":"Light/Switch","id":"000140AD","idx":93,"name":"Garage Door Back","nvalue":0,"stype":"Switch","svalue1":"Unlocked","switchType":"Door Lock","unit":1}

(This door is a virtual door currently locked/shut)

{"Battery":255,"RSSI":12,"description":"","dtype":"Light/Switch","id":"000140AF","idx":95,"name":"Garage Door Front Double","nvalue":1,"stype":"Switch","svalue1":"Locked","switchType":"Door Lock","unit":1}

(This is a ZWave lock, currently locked)

{"Battery":97,"RSSI":12,"description":"","dtype":"Light/Switch","id":"00000C01","idx":64,"name":"Back Door Lock","nvalue":1,"stype":"Switch","svalue1":"255","switchType":"Door Lock","unit":1}
t0mg commented 6 years ago

Ok, I've inverted the colors for this switch type (and made some styling tweaks)

locked: lock closed

unlocked: lock open

I think I can commit the change it you agree it looks ok.

sfeakes commented 6 years ago

I think it's perfect. Can't wait to see the changes.

sfeakes commented 6 years ago

Thanks so much, works perfectly and looks great.

t0mg commented 6 years ago

Glad to read that! Cheers