Unifi camera integration

Just want to share some integration of unifi G3 cameras into my openhab that has four items per camera:

  • Last recording time
  • Turn on/off motion detection recording
  • Status
  • Take camera snapshot

I use openhab 2.2 and had to make changes in the sitemap, item and the rules files.

<API key> is configured in the UniFi Video server on the admin account
<unifi video server> is the ip or address to your UniFi video server
<camera id> Take the camera id from rtsp service on your UniFi video server
Example: rtsp://172.17.0.2:7447/5a5a1b93e4b0b0b6e2fc8e8b_1
Will be camera id: 5a5a1b93e4b0b0b6e2fc8e8b

<Camera name> Used in the rules file, change to name that you named your camera

items file

String	cameraFront	"Camera Status [%s]" <camera>	{ http="<[http://<unifi video server>:7080/api/2.0/camera/<camera id>?apiKey=<API key>:60000:JSONPATH($.data[0].state)]" }
Number cameraFrontLastRecording	"Last recording [%d]" <time>	{ http="<[http://<unifi video server>:7080/api/2.0/camera/<camera id>?apiKey=<API key>:60000:JSONPATH($.data[0].lastRecordingStartTime)]" }
String cameraFrontLast "Last recording [%s]" <time>
String cameraFrontMotionState " [%s]" { http="<[http://<unifi video server>:7080/api/2.0/camera/<camera id>?apiKey=<API key>:10000:JSONPATH($.data[0].recordingSettings.motionRecordEnabled)]" }
Switch motionCameraFront "Motion detection" <motion>

sitemap

Text item=cameraFront valuecolor=[CONNECTED="green",DISCONNECTED="red"]
Text item=cameraFrontLast
Switch item=motionCameraFront
Image url="http://<unifi video server>:7080/api/2.0/snapshot/camera/<camera id>?apiKey=<API key>&width=500&force=true&t=1516046678" item=ImageURL refresh=10000

rules

import java.text.SimpleDateFormat
import java.util.Date

// Transform epoc time to human string
rule "cameraFrontLastRecording"
when
	Item cameraFrontLastRecording received update
then
  logInfo("cameraFrontLastRecording", "front:"+cameraFrontLastRecording.state)
  val timestampEpoch = (cameraFrontLastRecording.state as Number).longValue
	val SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
	val String timestampString = sdf.format(new Date(timestampEpoch))
  cameraFrontLast.sendCommand(""+timestampString)

end

// Camera front motion
rule "cameraFrontMotionState"
when
	Item cameraFrontMotionState received update
then
  logInfo("cameraFrontMotionState", "front motion state:"+cameraFrontMotionState.state)
  if(cameraFrontMotionState.state == "true"){
    motionCameraFront.sendCommand("ON");
  } else {
    motionCameraFront.sendCommand("OFF");
  }

end

rule "cameraFrontMotionChangeState"
when
	Item motionCameraFront received update
then
  var preStateChangeContent='{"name": "<Camera name>","recordingSettings": {"fullTimeRecordEnabled": false,"motionRecordEnabled":'
  var postStateChangeContent=',"channel": 0 }}'
  var httpUrl='http://<unifi video server>:7080/api/2.0/camera/<camera id>?apiKey=<API key>'

  logInfo("motionCameraFront", "front motion state change:"+motionCameraFront.state)

  if(motionCameraFront.state == ON){
    sendHttpPutRequest(httpUrl, "application/json", preStateChangeContent+'true'+postStateChangeContent)
  } else {
    sendHttpPutRequest(httpUrl, "application/json", preStateChangeContent+'false'+postStateChangeContent)
  }

end
// End Camera front motion
8 Likes

Thanks for posting. Please How to use code fences.

After doing that, go through and correct the quotes. when you paste in code without using code fences, not only is it really hard to read but the forum software replaces regular quotes " " with smart quotes “ ” which will not work when users paste in the rule and try to use it in their OH.

We love to see examples. Keep them coming!

Hi Patrik,

Thanks for sharing this. It works great!

Just as a feedback:

  • To make it work on my OH I’ve needed to install: HTTP Binding and JSONPath Transformation.
  • Another point is to add “http://” to the var httpUrl in the rule “cameraFrontMotionChangeState”, otherwise I was getting the error “Illegal character in scheme name at index 0:”.
  • And finally, I’ve also needed to remove the “item=ImageURL” on the definition of Image url in the sitemap file, otherwise I get the error: “Cannot retrieve item ‘ImageURL’ for widget org.eclipse.smarthome.model.sitemap.Image”

Kind regards,

Manuel MartĂ­nez

Just to save others from a bit of head scratching
 the http binding is still an openHAB 1 binding so you need to add ‘http1’ in the addons.cfg

Otherwise, working nicely.

Now I’m wondering if this would work reliably as a ‘PIR’ sensor to turn on the outside lights


Edit


Added a couple of items and the expire binding ‘expire1’

Contact cameraFrontMovemet “Front Movement [%s]” (gUniFiVideo) { expire=“5s,state=CLOSED” }
String cameraFrontLastRecordingOld

and updated the first rule

rule “cameraFrontLastRecording”
when
Item cameraFrontLastRecording received update
then
val timestampEpoch = (cameraFrontLastRecording.state as Number).longValue
val SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”)
val String timestampString = sdf.format(new Date(timestampEpoch))
cameraFrontLast.sendCommand(“”+timestampString)
if ((cameraFrontLastRecordingOld.state.toString) != (cameraFrontLastRecording.state.toString)) {
cameraFrontMovemet.sendCommand(OPEN)
cameraFrontLastRecordingOld.postUpdate(cameraFrontLastRecording.state.toString)
}
end

And it works quite well. May need to tweek my movement triger time and sensativity in UniFI Video and also the refresh rate for

Number cameraFrontLastRecording

But I think it could work quite well
 Got a few months until winter comes back to make it work!!!

I am implementing this now. Did you get any further with your testing on the motion side of things?

I may be missing it as I have yet to dive in to rules/code on this, but is there a way to start recording with Unifi/G3
 I am thinking of not using continuous recording, but dont want the camera motion detection to miss something when it finally detects motion. For example, I have a camera on my front porch that wont pick up motion of someone walking up the walk way. If I put a motion sensor that captures the motion out front ahead of where the camera motion detector can see
 I want to turn on recording early (and basically ignore the on camera motion detector) so as to potentially record the person/dog/cat etc walking in to the porch area. Currently the camera seems to miss a couple seconds by the time it picks up motion and records.

It would be fantastic if there was a continual “buffered” recording mode
 where by it records continuously a couple of seconds, then when it detects motion saves that couple of seconds and continues to record and save until motion has stopped for 15 seconds or so. No chance that works heh?

Yes there is
 The examples as listed above already contain the solution you are looking for.

The API allows for the control of both Continues and Motion based recording.
Take a look at a part of my JSON message allowing you to set these parameters for each individual camera.

I use this in combination with my Home State (Home, Away or Sleep) to enable/disable motion based recording.

'{"name": "Front Door","recordingSettings": {"fullTimeRecordEnabled": false,"motionRecordEnabled": true,"channel": 0 }}'

This example JSON sets FullTimeRecording to “false” and MotionRecording to “true”.

I use Node-Red for my rules processing so if you are interested i can show you what i have.

Br
Roel

Does anyone know if this works with Unifi Protect ? I had it working on my Windows based NVR then i switched to the Cloud Key Gen2 + and this way does not work on protect because there is not an API key generated.

Same question here, I moved to Unifi Protect and now I’m not sure anymore how to integrate in Openhab


Hi guys.
I know this discussion is a few month old, but since it is the first hit at google searching “unifi camera openhab” please let me push this thread.

First of all: the connection described above works perfect. Now I am interested in change recording settings based on if someone is home or not. The status of our four mobile phones (home or away) is already “known” in openhab by UniFi binding / setup.
@snoekieboe: I guess this is exactly what you already realized. Could you please share your code and - if needed - a few explanations?

Thanks!
wosch

As you can see below i use Node-Red for rule processing and to control the Unify NVR directly through it’s API.

The setup is extensive so i will need some time to post all the relevant code.
I will try to update this post later today ( if i find time )

Thanks a lot!
If it makes it easier for you I guess a few snippets will also help :slight_smile:

I had a look at the picture, really impressive what you did! :+1:

@wosch87
AS promised, i share with you my node-red based code/flows that i currently use to control the Unifi NVR through it’s api.

Unifi items in openhab

String UnifiNVR1IPAdress						"IP address [%s]"			<network>
String UnifiNVR1MongoDBVersion					"MongoDB version [%s]"		<pie>
String UnifiNVR1Version							"Software version [%s]"		<pie>
String UnifiNVR1Platform						"Platform version [%s]"		<pie>

String UnifiNVR1CAM1IPAdress					"IP address [%s]"			<network>
String UnifiNVR1CAM1Model						"Camera model [%s]"			<camera>
String UnifiNVR1CAM1Firmware					"Camera firmware [%s]"		<keyring>
DateTime UnifiNVR1CAM1LastSeen					"Last seen [%s]"			<time>	
String UnifiNVR1CAM1State						"Status [%s]"				<status>	
DateTime UnifiNVR1CAM1LastRecording				"Last recording [%s]"		<time>
String UnifiNVR1CAM1MotionRecording				"Motion recording [%s]"		<motion>
String UnifiNVR1CAM1FullRecording				"Full time recording [%s]"	<zoom>					
				
String UnifiNVR1CAM2IPAdress					"IP address [%s]"			<network>
String UnifiNVR1CAM2Model						"Camera model [%s]"			<camera>
String UnifiNVR1CAM2Firmware					"Camera firmware [%s]"		<keyring>
DateTime UnifiNVR1CAM2LastSeen					"Last seen [%s]"			<time>
String UnifiNVR1CAM2State						"Status [%s]"				<status>		
DateTime UnifiNVR1CAM2LastRecording				"Last recording [%s]"		<time>
String UnifiNVR1CAM2MotionRecording				"Motion recording [%s]"		<motion>
String UnifiNVR1CAM2FullRecording				"Full time recording [%s]"	<zoom>		

String UnifiNVR1CAM3IPAdress					"IP address [%s]"			<network>
String UnifiNVR1CAM3Model						"Camera model [%s]"			<camera>
String UnifiNVR1CAM3Firmware					"Camera firmware [%s]"		<keyring>
DateTime UnifiNVR1CAM3LastSeen					"Last seen [%s]"			<time>	
String UnifiNVR1CAM3State						"Status [%s]"				<status>		
DateTime UnifiNVR1CAM3LastRecording				"Last recording [%s]"		<time>
String UnifiNVR1CAM3MotionRecording				"Motion recording [%s]"		<motion>
String UnifiNVR1CAM3FullRecording				"Full time recording [%s]"	<zoom>		

String UnifiNVR1CAM4IPAdress					"IP address [%s]"			<network>
String UnifiNVR1CAM4Model						"Camera model [%s]"			<camera>
String UnifiNVR1CAM4Firmware					"Camera firmware [%s]"		<keyring>
DateTime UnifiNVR1CAM4LastSeen					"Last seen [%s]"			<time>	
String UnifiNVR1CAM4State						"Status [%s]"				<status>		
DateTime UnifiNVR1CAM4LastRecording				"Last recording [%s]"		<time>
String UnifiNVR1CAM4MotionRecording				"Motion recording [%s]"		<motion>
String UnifiNVR1CAM4FullRecording				"Full time recording [%s]"	<zoom>			
			

Nodered items in Openhab

String vLog						"Log [%s]"
String vNotification			"Notification [%s]"
String vPushover				"Pushover [%s]"
String vPushoverEmergency		"Pushover Emergency [%s]"
String vSound					"Sound [%s]"
String vSpeech					"Speech [%s]"

String vPushoverImage			"Pushover Image [%s]"
String vPushoverSound			"Pushover Sound [%s]"

String vDoorbellVideoOverlay	"[%s]"	(Group_HabPanel_Dashboard)

Nodered Rule 1: Set the Unifi camera recording state (no recording/full recording/motion recording) based on Openhab Home State (are we home, away or sleep)

[{"id":"556d189f.95b648","type":"http request","z":"6de6a755.eda798","name":"","method":"PUT","ret":"obj","url":"https://172.16.11.8:7443/api/2.0/camera/5c657086c2dce8e84384481b?apiKey=YOURAPIKEYHERE","tls":"","x":1270,"y":40,"wires":[[]]},{"id":"362172c8.439efe","type":"comment","z":"6de6a755.eda798","name":"Unifi NVR API - Set MotionRecording based on Home_State","info":"","x":240,"y":60,"wires":[]},{"id":"35c238ad.e70478","type":"function","z":"6de6a755.eda798","name":"set Front Door MotionRecording=True","func":"msg.payload = '{\"name\": \"Front Door\",\"recordingSettings\": {\"fullTimeRecordEnabled\": false,\"motionRecordEnabled\": true,\"channel\": 0 }}';\nreturn msg;","outputs":1,"noerr":0,"x":870,"y":40,"wires":[["24d6ea4f.466cc6"]]},{"id":"24d6ea4f.466cc6","type":"json","z":"6de6a755.eda798","name":"","property":"payload","action":"","pretty":false,"x":1130,"y":40,"wires":[["556d189f.95b648"]]},{"id":"c3fc5da6.0d132","type":"http request","z":"6de6a755.eda798","name":"","method":"PUT","ret":"obj","url":"https://172.16.11.8:7443/api/2.0/camera/5c6565f3c2dc7d1e99cbeff8?apiKey=YOURAPIKEYHERE","tls":"","x":1270,"y":80,"wires":[[]]},{"id":"d0197a6e.9762c8","type":"json","z":"6de6a755.eda798","name":"","property":"payload","action":"","pretty":false,"x":1130,"y":80,"wires":[["c3fc5da6.0d132"]]},{"id":"e5aabbec.b98108","type":"function","z":"6de6a755.eda798","name":"set Back Door MotionRecording=True","func":"msg.payload = '{\"name\": \"Back Door\",\"recordingSettings\": {\"fullTimeRecordEnabled\": false,\"motionRecordEnabled\": true,\"channel\": 0 }}';\nreturn msg;","outputs":1,"noerr":0,"x":870,"y":80,"wires":[["d0197a6e.9762c8"]]},{"id":"9550bf42.31778","type":"openhab2-in","z":"6de6a755.eda798","name":"Home_State","controller":"cc91af7c.15baf","itemname":"Home_State","x":90,"y":120,"wires":[[],["bd19a79c.0a1d28"]]},{"id":"bd19a79c.0a1d28","type":"switch","z":"6de6a755.eda798","name":"Item Updated","property":"payload.type","propertyType":"msg","rules":[{"t":"eq","v":"ItemStateEvent","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":280,"y":120,"wires":[["a79cf320.0462a"]]},{"id":"a79cf320.0462a","type":"switch","z":"6de6a755.eda798","name":"Evaluate Home State","property":"payload.payload.value","propertyType":"msg","rules":[{"t":"gte","v":"2","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":true,"outputs":2,"x":500,"y":120,"wires":[["35c238ad.e70478","e5aabbec.b98108","dc6b5aeb.5c28e8","36556edd.5b0992","5c59ab38.1236b4"],["685358e6.43aeb8","deba1823.0cee28","f2bf25a8.5215d8","46309ab1.c0bf64","a241934b.d2617"]]},{"id":"685358e6.43aeb8","type":"function","z":"6de6a755.eda798","name":"set Front Door MotionRecording=False","func":"msg.payload = '{\"name\": \"Front Door\",\"recordingSettings\": {\"fullTimeRecordEnabled\": false,\"motionRecordEnabled\": false,\"channel\": 0 }}';\nreturn msg;","outputs":1,"noerr":0,"x":870,"y":220,"wires":[["8e7bdb7b.37f0d8"]]},{"id":"deba1823.0cee28","type":"function","z":"6de6a755.eda798","name":"set Back Door MotionRecording=False","func":"msg.payload = '{\"name\": \"Back Door\",\"recordingSettings\": {\"fullTimeRecordEnabled\": false,\"motionRecordEnabled\": false,\"channel\": 0 }}';\nreturn msg;","outputs":1,"noerr":0,"x":870,"y":260,"wires":[["7a7ebdfc.6c3464"]]},{"id":"eda2ecb6.aa4b7","type":"http request","z":"6de6a755.eda798","name":"","method":"PUT","ret":"obj","url":"https://172.16.11.8:7443/api/2.0/camera/5c657086c2dce8e84384481b?apiKey=YOURAPIKEYHERE","tls":"","x":1290,"y":220,"wires":[[]]},{"id":"8e7bdb7b.37f0d8","type":"json","z":"6de6a755.eda798","name":"","property":"payload","action":"","pretty":false,"x":1140,"y":220,"wires":[["eda2ecb6.aa4b7"]]},{"id":"9f67cd5.54ff23","type":"http request","z":"6de6a755.eda798","name":"","method":"PUT","ret":"obj","url":"https://172.16.11.8:7443/api/2.0/camera/5c6565f3c2dc7d1e99cbeff8?apiKey=YOURAPIKEYHERE","tls":"","x":1290,"y":260,"wires":[[]]},{"id":"7a7ebdfc.6c3464","type":"json","z":"6de6a755.eda798","name":"","property":"payload","action":"","pretty":false,"x":1140,"y":260,"wires":[["9f67cd5.54ff23"]]},{"id":"de98b15a.41faa","type":"inject","z":"6de6a755.eda798","name":"Motion ON","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":580,"y":60,"wires":[["35c238ad.e70478","e5aabbec.b98108","36556edd.5b0992","5c59ab38.1236b4"]]},{"id":"754961a3.e9352","type":"inject","z":"6de6a755.eda798","name":"Motion OFF","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":570,"y":240,"wires":[["685358e6.43aeb8","deba1823.0cee28","46309ab1.c0bf64","a241934b.d2617"]]},{"id":"5b4861a1.05274","type":"openhab2-out","z":"6de6a755.eda798","name":"vLog","controller":"cc91af7c.15baf","itemname":"vLog","topic":"ItemUpdate","payload":"","x":990,"y":400,"wires":[[]]},{"id":"f2bf25a8.5215d8","type":"change","z":"6de6a755.eda798","name":"Create Log Entry","rules":[{"t":"set","p":"payload","pt":"msg","to":"NR - Unifi NVR - Disable Motion Recording because Home State = HOME","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":420,"wires":[["5b4861a1.05274"]]},{"id":"dc6b5aeb.5c28e8","type":"change","z":"6de6a755.eda798","name":"Create Log Entry","rules":[{"t":"set","p":"payload","pt":"msg","to":"NR - Unifi NVR - Enable Motion Recording because Home State = AWAY/SLEEP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":380,"wires":[["5b4861a1.05274"]]},{"id":"36556edd.5b0992","type":"function","z":"6de6a755.eda798","name":"set Terrace MotionRecording=True","func":"msg.payload = '{\"name\": \"Terras\",\"recordingSettings\": {\"fullTimeRecordEnabled\": false,\"motionRecordEnabled\": true,\"channel\": 0 }}';\nreturn msg;","outputs":1,"noerr":0,"x":860,"y":120,"wires":[["c0b17d7.f92378"]]},{"id":"5c59ab38.1236b4","type":"function","z":"6de6a755.eda798","name":"set Living Room MotionRecording=True","func":"msg.payload = '{\"name\": \"Woonkamer\",\"recordingSettings\": {\"fullTimeRecordEnabled\": false,\"motionRecordEnabled\": true,\"channel\": 0 }}';\nreturn msg;","outputs":1,"noerr":0,"x":880,"y":160,"wires":[["1e1d69f3.2248b6"]]},{"id":"ad92a38d.ad831","type":"http request","z":"6de6a755.eda798","name":"","method":"PUT","ret":"obj","paytoqs":false,"url":"https://172.16.11.8:7443/api/2.0/camera/5ca496b1c2dc81ba62d374ae?apiKey=YOURAPIKEYHERE","tls":"","proxy":"","x":1270,"y":120,"wires":[[]]},{"id":"c0b17d7.f92378","type":"json","z":"6de6a755.eda798","name":"","property":"payload","action":"","pretty":false,"x":1130,"y":120,"wires":[["ad92a38d.ad831"]]},{"id":"eb363e95.747dc","type":"http request","z":"6de6a755.eda798","name":"","method":"PUT","ret":"obj","paytoqs":false,"url":"https://172.16.11.8:7443/api/2.0/camera/5cb1baddc2dc13a0c0f910ff?apiKey=YOURAPIKEYHERE","tls":"","proxy":"","x":1270,"y":160,"wires":[[]]},{"id":"1e1d69f3.2248b6","type":"json","z":"6de6a755.eda798","name":"","property":"payload","action":"","pretty":false,"x":1130,"y":160,"wires":[["eb363e95.747dc"]]},{"id":"46309ab1.c0bf64","type":"function","z":"6de6a755.eda798","name":"set Terrace MotionRecording=False","func":"msg.payload = '{\"name\": \"Terras\",\"recordingSettings\": {\"fullTimeRecordEnabled\": false,\"motionRecordEnabled\": false,\"channel\": 0 }}';\nreturn msg;","outputs":1,"noerr":0,"x":860,"y":300,"wires":[["471f8e90.fb626"]]},{"id":"a241934b.d2617","type":"function","z":"6de6a755.eda798","name":"set Living Room MotionRecording=False","func":"msg.payload = '{\"name\": \"Woonkamer\",\"recordingSettings\": {\"fullTimeRecordEnabled\": false,\"motionRecordEnabled\": false,\"channel\": 0 }}';\nreturn msg;","outputs":1,"noerr":0,"x":880,"y":340,"wires":[["5f618063.621f7"]]},{"id":"471f8e90.fb626","type":"json","z":"6de6a755.eda798","name":"","property":"payload","action":"","pretty":false,"x":1140,"y":300,"wires":[["78d51a36.84a784"]]},{"id":"5f618063.621f7","type":"json","z":"6de6a755.eda798","name":"","property":"payload","action":"","pretty":false,"x":1140,"y":340,"wires":[["218ef04f.595f3"]]},{"id":"78d51a36.84a784","type":"http request","z":"6de6a755.eda798","name":"","method":"PUT","ret":"obj","paytoqs":false,"url":"https://172.16.11.8:7443/api/2.0/camera/5ca496b1c2dc81ba62d374ae?apiKey=YOURAPIKEYHERE","tls":"","proxy":"","x":1290,"y":300,"wires":[[]]},{"id":"218ef04f.595f3","type":"http request","z":"6de6a755.eda798","name":"","method":"PUT","ret":"obj","paytoqs":false,"url":"https://172.16.11.8:7443/api/2.0/camera/5cb1baddc2dc13a0c0f910ff?apiKey=YOURAPIKEYHERE","tls":"","proxy":"","x":1290,"y":340,"wires":[[]]},{"id":"cc91af7c.15baf","type":"openhab2-controller","z":"","name":"Openhab2 - Prod","protocol":"http","host":"localhost","port":"8080","path":"","username":"","password":""}]

Nodered Rule 2: Set the Unifi frontdoor camera recording state to full recording for x minutes if the doorbell is pressed*

[{"id":"dec12ab3.c25538","type":"openhab2-in","z":"6de6a755.eda798","name":"Doorbell","controller":"cc91af7c.15baf","itemname":"Doorbell","x":80,"y":460,"wires":[[],["9ac88bd6.93cbd8"]]},{"id":"9ac88bd6.93cbd8","type":"switch","z":"6de6a755.eda798","name":"Item Updated","property":"payload.type","propertyType":"msg","rules":[{"t":"eq","v":"ItemStateEvent","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":260,"y":460,"wires":[["277842c7.bc0abe"]]},{"id":"277842c7.bc0abe","type":"switch","z":"6de6a755.eda798","name":"Evaluate Doorbell","property":"payload.payload.value","propertyType":"msg","rules":[{"t":"eq","v":"ON","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":460,"wires":[["8df1e277.2c9e2"]]},{"id":"812ae479.b3bc88","type":"comment","z":"6de6a755.eda798","name":"Unifi NVR API - Record when doorbell pressed","info":"","x":200,"y":420,"wires":[]},{"id":"faeb36b9.789ad8","type":"function","z":"6de6a755.eda798","name":"set Front Door Full Time Recording=True","func":"msg.payload = '{\"name\": \"Front Door\",\"recordingSettings\": {\"fullTimeRecordEnabled\": true,\"motionRecordEnabled\": false,\"channel\": 0 }}';\nreturn msg;","outputs":1,"noerr":0,"x":1720,"y":440,"wires":[["6c8940d.fae3ec"]]},{"id":"5ebfefd.4e37c1","type":"function","z":"6de6a755.eda798","name":"set Front Door Full Time Recording=False","func":"msg.payload = '{\"name\": \"Front Door\",\"recordingSettings\": {\"fullTimeRecordEnabled\": false,\"motionRecordEnabled\": false,\"channel\": 0 }}';\nreturn msg;","outputs":1,"noerr":0,"x":1720,"y":480,"wires":[["6c8940d.fae3ec"]]},{"id":"4f4ebf8.e3c374","type":"trigger","z":"6de6a755.eda798","op1":"ON","op2":"OFF","op1type":"str","op2type":"str","duration":"2","extend":true,"units":"min","reset":"","bytopic":"all","name":"Turn ON then OFF after 2 minute","x":1160,"y":460,"wires":[["35506469.69936c"]]},{"id":"35506469.69936c","type":"switch","z":"6de6a755.eda798","name":"Evaluate payload","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"ON","vt":"str"},{"t":"eq","v":"OFF","vt":"str"}],"checkall":"true","repair":true,"outputs":2,"x":1430,"y":460,"wires":[["faeb36b9.789ad8"],["5ebfefd.4e37c1"]]},{"id":"3518260a.444a6a","type":"http request","z":"6de6a755.eda798","name":"","method":"PUT","ret":"obj","url":"https://172.16.11.8:7443/api/2.0/camera/5c657086c2dce8e84384481b?apiKey=YOURAPIKEYHERE","tls":"","x":2130,"y":460,"wires":[[]]},{"id":"6c8940d.fae3ec","type":"json","z":"6de6a755.eda798","name":"","property":"payload","action":"","pretty":false,"x":1970,"y":460,"wires":[["3518260a.444a6a"]]},{"id":"8df1e277.2c9e2","type":"openhab2-get","z":"6de6a755.eda798","name":"Home State","controller":"cc91af7c.15baf","itemname":"Home_State","x":670,"y":460,"wires":[["b0646507.b93968","4f4ebf8.e3c374"]]},{"id":"cc91af7c.15baf","type":"openhab2-controller","z":"","name":"Openhab2 - Prod","protocol":"http","host":"localhost","port":"8080","path":"","username":"","password":""}]

Nodered Rule 3: Grab camera status/details from Unifi API and update corresponding Openhab Items*

[{"id":"16c2e471.1655ec","type":"http request","z":"6de6a755.eda798","name":"","method":"GET","ret":"obj","url":"https://172.16.11.8:7443/api/2.0/camera/5c657086c2dce8e84384481b?apiKey=YOURAPIKEYHERE","tls":"","x":270,"y":720,"wires":[["21838b0f.211184"]]},{"id":"4b7739d.38992c8","type":"inject","z":"6de6a755.eda798","name":"Trigger every 30s","topic":"","payload":"","payloadType":"date","repeat":"30","crontab":"","once":false,"onceDelay":"30","x":110,"y":880,"wires":[["16c2e471.1655ec","2f315aa6.c418b6","ee0f951a.f24818","c8893098.3fb79"]]},{"id":"a215e161.1ee98","type":"comment","z":"6de6a755.eda798","name":"Unifi API - Grab Front Door Camera details","info":"","x":180,"y":680,"wires":[]},{"id":"21838b0f.211184","type":"splitter","z":"6de6a755.eda798","name":"","property":"payload.data","x":430,"y":720,"wires":[["c556048d.bb0838","989b2ef9.050b1","5ff4f005.13f47","386a93fe.d1f2ac","253c5686.1ed11a","bb419f4c.73678","3c94d146.961a5e","6aafefdb.8b147"]]},{"id":"c556048d.bb0838","type":"change","z":"6de6a755.eda798","name":"Camera IP Address","rules":[{"t":"move","p":"payload.host","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":680,"wires":[["b25c7bc9.1c8028"]]},{"id":"989b2ef9.050b1","type":"change","z":"6de6a755.eda798","name":"Camera Model","rules":[{"t":"move","p":"payload.model","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":720,"wires":[["9ee2ea8c.8342a8"]]},{"id":"5ff4f005.13f47","type":"change","z":"6de6a755.eda798","name":"Camera Firmware","rules":[{"t":"move","p":"payload.firmwareVersion","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":760,"wires":[["d551a9f4.090be8"]]},{"id":"386a93fe.d1f2ac","type":"change","z":"6de6a755.eda798","name":"Camera Last Seen","rules":[{"t":"move","p":"payload.lastSeen","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":800,"wires":[["b32cd9aa.be5f68"]]},{"id":"253c5686.1ed11a","type":"change","z":"6de6a755.eda798","name":"Camera State","rules":[{"t":"move","p":"payload.state","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":840,"wires":[["3624003f.4a485"]]},{"id":"bb419f4c.73678","type":"change","z":"6de6a755.eda798","name":"Camera Last Recording","rules":[{"t":"move","p":"payload.lastRecordingStartTime","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":880,"wires":[["cee418ce.64c228"]]},{"id":"3c94d146.961a5e","type":"change","z":"6de6a755.eda798","name":"Camera Motion Recording","rules":[{"t":"move","p":"payload.recordingSettings.motionRecordEnabled","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":920,"wires":[["10dab47.e6a804c"]]},{"id":"6aafefdb.8b147","type":"change","z":"6de6a755.eda798","name":"Camera Full Time Recording","rules":[{"t":"move","p":"payload.recordingSettings.fullTimeRecordEnabled","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":960,"wires":[["a8f0347b.a6fa18"]]},{"id":"b25c7bc9.1c8028","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM1IPAdress","topic":"ItemUpdate","payload":"","x":1170,"y":680,"wires":[[]]},{"id":"9ee2ea8c.8342a8","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM1Model","topic":"ItemUpdate","payload":"","x":1160,"y":720,"wires":[[]]},{"id":"d551a9f4.090be8","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM1Firmware","topic":"ItemUpdate","payload":"","x":1170,"y":760,"wires":[[]]},{"id":"fc358b6f.11a668","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM1LastSeen","topic":"ItemUpdate","payload":"","x":1170,"y":800,"wires":[[]]},{"id":"3624003f.4a485","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM1State","topic":"ItemUpdate","payload":"","x":1160,"y":840,"wires":[[]]},{"id":"945a20bd.0343b","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM1LastRecording","topic":"ItemUpdate","payload":"","x":1190,"y":880,"wires":[[]]},{"id":"10dab47.e6a804c","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM1MotionRecording","topic":"ItemUpdate","payload":"","x":1200,"y":920,"wires":[[]]},{"id":"a8f0347b.a6fa18","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM1FullRecording","topic":"ItemUpdate","payload":"","x":1190,"y":960,"wires":[[]]},{"id":"cee418ce.64c228","type":"moment","z":"6de6a755.eda798","name":"","topic":"","input":"","inputType":"msg","inTz":"Europe/Amsterdam","adjAmount":"1","adjType":"hours","adjDir":"add","format":"","locale":"eu_NL","output":"","outputType":"msg","outTz":"Europe/Amsterdam","x":920,"y":880,"wires":[["945a20bd.0343b"]]},{"id":"b32cd9aa.be5f68","type":"moment","z":"6de6a755.eda798","name":"","topic":"","input":"","inputType":"msg","inTz":"Europe/Amsterdam","adjAmount":"1","adjType":"hours","adjDir":"add","format":"","locale":"eu_NL","output":"","outputType":"msg","outTz":"Europe/Amsterdam","x":920,"y":800,"wires":[["fc358b6f.11a668"]]},{"id":"2f315aa6.c418b6","type":"http request","z":"6de6a755.eda798","name":"","method":"GET","ret":"obj","url":"https://172.16.11.8:7443/api/2.0/camera/5c6565f3c2dc7d1e99cbeff8?apiKey=YOURAPIKEYHERE","tls":"","x":270,"y":1060,"wires":[["22683afa.022986"]]},{"id":"71cb07dc.3bca98","type":"comment","z":"6de6a755.eda798","name":"Unifi API - Grab Back Door Camera details","info":"","x":180,"y":1020,"wires":[]},{"id":"22683afa.022986","type":"splitter","z":"6de6a755.eda798","name":"","property":"payload.data","x":430,"y":1060,"wires":[["e9492f75.eb2de","5818ef27.1b251","df32dadc.e75188","96622622.fa3ec8","43469214.e94e2c","20907bec.48ba34","ceadbf5b.2820c","4488a156.259cf"]]},{"id":"e9492f75.eb2de","type":"change","z":"6de6a755.eda798","name":"Camera IP Address","rules":[{"t":"move","p":"payload.host","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":1020,"wires":[["5cacf9ad.b69848"]]},{"id":"5818ef27.1b251","type":"change","z":"6de6a755.eda798","name":"Camera Model","rules":[{"t":"move","p":"payload.model","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":1060,"wires":[["670ec4fe.ee113c"]]},{"id":"df32dadc.e75188","type":"change","z":"6de6a755.eda798","name":"Camera Firmware","rules":[{"t":"move","p":"payload.firmwareVersion","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":1100,"wires":[["1a282c43.f9f184"]]},{"id":"96622622.fa3ec8","type":"change","z":"6de6a755.eda798","name":"Camera Last Seen","rules":[{"t":"move","p":"payload.lastSeen","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":1140,"wires":[["af1ed38a.9a19a"]]},{"id":"43469214.e94e2c","type":"change","z":"6de6a755.eda798","name":"Camera State","rules":[{"t":"move","p":"payload.state","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":1180,"wires":[["9e8af8f.a1db308"]]},{"id":"20907bec.48ba34","type":"change","z":"6de6a755.eda798","name":"Camera Last Recording","rules":[{"t":"move","p":"payload.lastRecordingStartTime","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":1220,"wires":[["280f31aa.8bcb4e"]]},{"id":"ceadbf5b.2820c","type":"change","z":"6de6a755.eda798","name":"Camera Motion Recording","rules":[{"t":"move","p":"payload.recordingSettings.motionRecordEnabled","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":1260,"wires":[["bee3e9a0.2f27a8"]]},{"id":"4488a156.259cf","type":"change","z":"6de6a755.eda798","name":"Camera Full Time Recording","rules":[{"t":"move","p":"payload.recordingSettings.fullTimeRecordEnabled","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":1300,"wires":[["42354b09.1340a4"]]},{"id":"5cacf9ad.b69848","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM2IPAdress","topic":"ItemUpdate","payload":"","x":1170,"y":1020,"wires":[[]]},{"id":"670ec4fe.ee113c","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM2Model","topic":"ItemUpdate","payload":"","x":1160,"y":1060,"wires":[[]]},{"id":"1a282c43.f9f184","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM2Firmware","topic":"ItemUpdate","payload":"","x":1170,"y":1100,"wires":[[]]},{"id":"d4950553.9311e8","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM2LastSeen","topic":"ItemUpdate","payload":"","x":1170,"y":1140,"wires":[[]]},{"id":"9e8af8f.a1db308","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM2State","topic":"ItemUpdate","payload":"","x":1160,"y":1180,"wires":[[]]},{"id":"78fc7b4b.8a81d4","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM2LastRecording","topic":"ItemUpdate","payload":"","x":1190,"y":1220,"wires":[[]]},{"id":"bee3e9a0.2f27a8","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM2MotionRecording","topic":"ItemUpdate","payload":"","x":1200,"y":1260,"wires":[[]]},{"id":"42354b09.1340a4","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM2FullRecording","topic":"ItemUpdate","payload":"","x":1190,"y":1300,"wires":[[]]},{"id":"280f31aa.8bcb4e","type":"moment","z":"6de6a755.eda798","name":"","topic":"","input":"","inputType":"msg","inTz":"Europe/Amsterdam","adjAmount":"1","adjType":"hours","adjDir":"add","format":"","locale":"eu_NL","output":"","outputType":"msg","outTz":"Europe/Amsterdam","x":920,"y":1220,"wires":[["78fc7b4b.8a81d4"]]},{"id":"af1ed38a.9a19a","type":"moment","z":"6de6a755.eda798","name":"","topic":"","input":"","inputType":"msg","inTz":"Europe/Amsterdam","adjAmount":"1","adjType":"hours","adjDir":"add","format":"","locale":"eu_NL","output":"","outputType":"msg","outTz":"Europe/Amsterdam","x":920,"y":1140,"wires":[["d4950553.9311e8"]]},{"id":"ee0f951a.f24818","type":"http request","z":"6de6a755.eda798","name":"","method":"GET","ret":"obj","paytoqs":false,"url":"https://172.16.11.8:7443/api/2.0/camera/5ca496b1c2dc81ba62d374ae?apiKey=YOURAPIKEYHERE","tls":"","proxy":"","x":270,"y":1420,"wires":[["e008de6a.4a029"]]},{"id":"3b12244b.49abcc","type":"comment","z":"6de6a755.eda798","name":"Unifi API - Grab Terrace Camera details","info":"","x":170,"y":1380,"wires":[]},{"id":"e008de6a.4a029","type":"splitter","z":"6de6a755.eda798","name":"","property":"payload.data","x":430,"y":1420,"wires":[["ea173262.3134b","3c51e06d.5fc0c","4b0ea13b.45219","dbd10559.412e58","5cc3e598.db4f5c","91e8fe2e.62d1e","44f17714.6f22a8","b6c6f2c8.075bd"]]},{"id":"ea173262.3134b","type":"change","z":"6de6a755.eda798","name":"Camera IP Address","rules":[{"t":"move","p":"payload.host","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":1380,"wires":[["5e160158.e5e57"]]},{"id":"3c51e06d.5fc0c","type":"change","z":"6de6a755.eda798","name":"Camera Model","rules":[{"t":"move","p":"payload.model","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":1420,"wires":[["6526d31c.87831c"]]},{"id":"4b0ea13b.45219","type":"change","z":"6de6a755.eda798","name":"Camera Firmware","rules":[{"t":"move","p":"payload.firmwareVersion","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":1460,"wires":[["1b06cc41.510034"]]},{"id":"dbd10559.412e58","type":"change","z":"6de6a755.eda798","name":"Camera Last Seen","rules":[{"t":"move","p":"payload.lastSeen","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":1500,"wires":[["270afcf8.d14c54"]]},{"id":"5cc3e598.db4f5c","type":"change","z":"6de6a755.eda798","name":"Camera State","rules":[{"t":"move","p":"payload.state","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":1540,"wires":[["a707a46c.c33348"]]},{"id":"91e8fe2e.62d1e","type":"change","z":"6de6a755.eda798","name":"Camera Last Recording","rules":[{"t":"move","p":"payload.lastRecordingStartTime","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":1580,"wires":[["9569dfcb.97b0d"]]},{"id":"44f17714.6f22a8","type":"change","z":"6de6a755.eda798","name":"Camera Motion Recording","rules":[{"t":"move","p":"payload.recordingSettings.motionRecordEnabled","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":1620,"wires":[["b9604c15.41aeb"]]},{"id":"b6c6f2c8.075bd","type":"change","z":"6de6a755.eda798","name":"Camera Full Time Recording","rules":[{"t":"move","p":"payload.recordingSettings.fullTimeRecordEnabled","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":1660,"wires":[["c99f26ca.007548"]]},{"id":"5e160158.e5e57","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM3IPAdress","topic":"ItemUpdate","payload":"","x":1170,"y":1380,"wires":[[]]},{"id":"6526d31c.87831c","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM3Model","topic":"ItemUpdate","payload":"","x":1160,"y":1420,"wires":[[]]},{"id":"1b06cc41.510034","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM3Firmware","topic":"ItemUpdate","payload":"","x":1170,"y":1460,"wires":[[]]},{"id":"8a343de8.9e07","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM3LastSeen","topic":"ItemUpdate","payload":"","x":1170,"y":1500,"wires":[[]]},{"id":"a707a46c.c33348","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM3State","topic":"ItemUpdate","payload":"","x":1160,"y":1540,"wires":[[]]},{"id":"141a3673.3f584a","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM3LastRecording","topic":"ItemUpdate","payload":"","x":1190,"y":1580,"wires":[[]]},{"id":"b9604c15.41aeb","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM3MotionRecording","topic":"ItemUpdate","payload":"","x":1200,"y":1620,"wires":[[]]},{"id":"c99f26ca.007548","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM3FullRecording","topic":"ItemUpdate","payload":"","x":1190,"y":1660,"wires":[[]]},{"id":"9569dfcb.97b0d","type":"moment","z":"6de6a755.eda798","name":"","topic":"","input":"","inputType":"msg","inTz":"Europe/Amsterdam","adjAmount":"1","adjType":"hours","adjDir":"add","format":"","locale":"eu_NL","output":"","outputType":"msg","outTz":"Europe/Amsterdam","x":920,"y":1580,"wires":[["141a3673.3f584a"]]},{"id":"270afcf8.d14c54","type":"moment","z":"6de6a755.eda798","name":"","topic":"","input":"","inputType":"msg","inTz":"Europe/Amsterdam","adjAmount":"1","adjType":"hours","adjDir":"add","format":"","locale":"eu_NL","output":"","outputType":"msg","outTz":"Europe/Amsterdam","x":920,"y":1500,"wires":[["8a343de8.9e07"]]},{"id":"c8893098.3fb79","type":"http request","z":"6de6a755.eda798","name":"","method":"GET","ret":"obj","paytoqs":false,"url":"https://172.16.11.8:7443/api/2.0/camera/5cb1baddc2dc13a0c0f910ff?apiKey=YOURAPIKEYHERE","tls":"","proxy":"","x":270,"y":1780,"wires":[["51cce2b2.cc1bec"]]},{"id":"c04b2212.2ac1c","type":"comment","z":"6de6a755.eda798","name":"Unifi API - Grab Living Room Camera details","info":"","x":190,"y":1740,"wires":[]},{"id":"51cce2b2.cc1bec","type":"splitter","z":"6de6a755.eda798","name":"","property":"payload.data","x":430,"y":1780,"wires":[["644bb30.8021f4c","57883400.a9047c","f8cc6352.08bcb","5030bdff.9949a4","1f03d570.dfbb7b","3ca014e7.ea17bc","a55dc30e.56c8f","c654a4bf.8c2a58"]]},{"id":"644bb30.8021f4c","type":"change","z":"6de6a755.eda798","name":"Camera IP Address","rules":[{"t":"move","p":"payload.host","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":1740,"wires":[["b5c12fad.db322"]]},{"id":"57883400.a9047c","type":"change","z":"6de6a755.eda798","name":"Camera Model","rules":[{"t":"move","p":"payload.model","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":1780,"wires":[["4a87ac72.d9b554"]]},{"id":"f8cc6352.08bcb","type":"change","z":"6de6a755.eda798","name":"Camera Firmware","rules":[{"t":"move","p":"payload.firmwareVersion","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":1820,"wires":[["5494f558.4f7d7c"]]},{"id":"5030bdff.9949a4","type":"change","z":"6de6a755.eda798","name":"Camera Last Seen","rules":[{"t":"move","p":"payload.lastSeen","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":1860,"wires":[["d906247e.1bf878"]]},{"id":"1f03d570.dfbb7b","type":"change","z":"6de6a755.eda798","name":"Camera State","rules":[{"t":"move","p":"payload.state","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":1900,"wires":[["7a2c9d10.34e324"]]},{"id":"3ca014e7.ea17bc","type":"change","z":"6de6a755.eda798","name":"Camera Last Recording","rules":[{"t":"move","p":"payload.lastRecordingStartTime","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":1940,"wires":[["10d5587d.c0c2a8"]]},{"id":"a55dc30e.56c8f","type":"change","z":"6de6a755.eda798","name":"Camera Motion Recording","rules":[{"t":"move","p":"payload.recordingSettings.motionRecordEnabled","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":1980,"wires":[["d994f3b3.93cad"]]},{"id":"c654a4bf.8c2a58","type":"change","z":"6de6a755.eda798","name":"Camera Full Time Recording","rules":[{"t":"move","p":"payload.recordingSettings.fullTimeRecordEnabled","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":2020,"wires":[["f72970a9.6efdf"]]},{"id":"b5c12fad.db322","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM4IPAdress","topic":"ItemUpdate","payload":"","x":1170,"y":1740,"wires":[[]]},{"id":"4a87ac72.d9b554","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM4Model","topic":"ItemUpdate","payload":"","x":1160,"y":1780,"wires":[[]]},{"id":"5494f558.4f7d7c","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM4Firmware","topic":"ItemUpdate","payload":"","x":1170,"y":1820,"wires":[[]]},{"id":"a96f916f.501f1","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM4LastSeen","topic":"ItemUpdate","payload":"","x":1170,"y":1860,"wires":[[]]},{"id":"7a2c9d10.34e324","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM4State","topic":"ItemUpdate","payload":"","x":1160,"y":1900,"wires":[[]]},{"id":"7a0ec153.213a5","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM4LastRecording","topic":"ItemUpdate","payload":"","x":1190,"y":1940,"wires":[[]]},{"id":"d994f3b3.93cad","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM4MotionRecording","topic":"ItemUpdate","payload":"","x":1200,"y":1980,"wires":[[]]},{"id":"f72970a9.6efdf","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1CAM4FullRecording","topic":"ItemUpdate","payload":"","x":1190,"y":2020,"wires":[[]]},{"id":"10d5587d.c0c2a8","type":"moment","z":"6de6a755.eda798","name":"","topic":"","input":"","inputType":"msg","inTz":"Europe/Amsterdam","adjAmount":"1","adjType":"hours","adjDir":"add","format":"","locale":"eu_NL","output":"","outputType":"msg","outTz":"Europe/Amsterdam","x":920,"y":1940,"wires":[["7a0ec153.213a5"]]},{"id":"d906247e.1bf878","type":"moment","z":"6de6a755.eda798","name":"","topic":"","input":"","inputType":"msg","inTz":"Europe/Amsterdam","adjAmount":"1","adjType":"hours","adjDir":"add","format":"","locale":"eu_NL","output":"","outputType":"msg","outTz":"Europe/Amsterdam","x":920,"y":1860,"wires":[["a96f916f.501f1"]]},{"id":"df8e0269.b6ba4","type":"http request","z":"6de6a755.eda798","name":"","method":"GET","ret":"obj","url":"https://172.16.11.8:7443/api/2.0/sysinfo?apiKey=YOURAPIKEYHERE","tls":"","x":270,"y":2140,"wires":[["779a684f.5deb58"]]},{"id":"b00cf9f2.541698","type":"inject","z":"6de6a755.eda798","name":"Trigger every hour","topic":"","payload":"","payloadType":"date","repeat":"3600","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":2140,"wires":[["df8e0269.b6ba4"]]},{"id":"e0fc7b1f.1c7258","type":"comment","z":"6de6a755.eda798","name":"Unifi API - Sysinfo","info":"","x":110,"y":2100,"wires":[]},{"id":"779a684f.5deb58","type":"splitter","z":"6de6a755.eda798","name":"","property":"payload.data","x":430,"y":2140,"wires":[["97decce5.ab477"]]},{"id":"759d9fc6.81f0d","type":"change","z":"6de6a755.eda798","name":"NVR IP Address","rules":[{"t":"move","p":"payload.localAddr","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":2080,"wires":[["bde5a47b.996c08"]]},{"id":"efeae5db.ea3ba8","type":"change","z":"6de6a755.eda798","name":"NVR MongoDB version","rules":[{"t":"move","p":"payload.mongoVersion","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":2120,"wires":[["589a892a.cc63a8"]]},{"id":"bbc7f843.a5d6b8","type":"change","z":"6de6a755.eda798","name":"NVR Version","rules":[{"t":"move","p":"payload.version","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":2160,"wires":[["d8d4c5bd.018958"]]},{"id":"13e5bc90.7d3093","type":"change","z":"6de6a755.eda798","name":"NVR Platform Version","rules":[{"t":"move","p":"payload.platform","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":2200,"wires":[["155c557b.e72eeb"]]},{"id":"155c557b.e72eeb","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1Platform","topic":"ItemUpdate","payload":"","x":1050,"y":2200,"wires":[[]]},{"id":"d8d4c5bd.018958","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1Version","topic":"ItemUpdate","payload":"","x":1050,"y":2160,"wires":[[]]},{"id":"589a892a.cc63a8","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1MongoDBVersion","topic":"ItemUpdate","payload":"","x":1080,"y":2120,"wires":[[]]},{"id":"bde5a47b.996c08","type":"openhab2-out","z":"6de6a755.eda798","name":"","controller":"cc91af7c.15baf","itemname":"UnifiNVR1IPAdress","topic":"ItemUpdate","payload":"","x":1050,"y":2080,"wires":[[]]},{"id":"97decce5.ab477","type":"rbe","z":"6de6a755.eda798","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":570,"y":2140,"wires":[["759d9fc6.81f0d","efeae5db.ea3ba8","bbc7f843.a5d6b8","13e5bc90.7d3093"]]},{"id":"cc91af7c.15baf","type":"openhab2-controller","z":"","name":"Openhab2 - Prod","protocol":"http","host":"localhost","port":"8080","path":"","username":"","password":""}]

Some pointers to get this up and running:

  • You can import the node-red rules through copy & past using the clipboard function in node-red
  • You need to configure your own api key in Unifi NVR and insert that wherever the code says " YOURAPIKEYHERE"
  • also make sure the URL matches your URL (e.g. IP Address)
  • To get the correct camera ID you need to enable RTSP for each camera. The unifi NVR will then show you the unique URL for each camera and this is required to communicate correclty with the NVR
1 Like

Hello,

the first example worked fine for me since yesterday when i updated to 2.5.1. Now it don’t shows the snapshot image anymore
 Any idea?
Oliver

News:
after reinstalation of jsonpath transformation it worked

so soluted !

Hi,
Here is an update of the Unifi camera integration for openhab 3.0
Remember that Unifi Video is end of life
Push notifications are then not working so in this example I will use pushover service to continue to get push notifications.

Note: Remember to change following things to your values

  • <unifi video server>
  • <camera id>
  • <API key>
  • <Your pushover API key>
  • <Your pushover user key>

wget need to be installed on your openhab server

Some links to the addons and service:
pushover
http
exec
jsonpath
Pushover service (This currently have one-time fee to use)

addons.cfg

Binding = exec, http, pushover
Transformation =jsonpath

exec.whitelist

/usr/bin/wget 'http://<unifi video server>:7080/api/2.0/snapshot/camera/<camera id>?apiKey=<API key>&width=500&force=true&t=1516046678' -O /tmp/garage.jpg

things file

Thing http:url:cameraGarage "Garage Camera" [ baseURL="http://<unifi video server>:7080/api/2.0/camera/<camera id>?apiKey=<API key>", refresh=10] {
    Channels:
        Type number : lastRec "Last Rec" [ stateTransformation="JSONPATH:$.data[0].lastRecordingStartTime" ]
        Type string : status "Status" [ stateTransformation="JSONPATH:$.data[0].state" ]
        Type string : motion "Motion" [ stateTransformation="JSONPATH:$.data[0].recordingSettings.motionRecordEnabled" ]
}

Thing exec:command:cameraGarage "cameraGarageExec" [command="/usr/bin/wget 'http://<unifi video server>:7080/api/2.0/snapshot/camera/<camera id>?apiKey=<API key>&width=500&force=true&t=1516046678' -O /tmp/garage.jpg", interval=0, timeout=10, autorun=false]

Thing pushover:pushover-account:account [ apikey="<Your pushover API key>", user="<Your pushover user key>" ]

items file

String	cameraGarage "Garage Status [%s]" <camera>	{ channel="http:url:cameraGarage:status" }
Number cameraGarageLastRecording	"Last recording [%d]" <time>	{ channel="http:url:cameraGarage:lastRec" }
String cameraGarageLast "Last recording [%s]" <time>
String cameraGarageMotionState " [%s]" { channel="http:url:cameraGarage:motion" }
Switch motionCameraGarage "Motion detection" <motion>
Switch cameraGarageSnapshot "Camera snapshot" { channel="exec:command:cameraGarage:run"}

rules file

import java.text.SimpleDateFormat
import java.util.Date
var long cameraGaragePrevMotion = 1

rule "cameraGarageLastRecording"
when
	Item cameraGarageLastRecording received update
then
  val timestampEpoch = (cameraGarageLastRecording.state as Number).longValue
	val SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
	val String timestampString = sdf.format(new Date(timestampEpoch))
  cameraGarageLast.sendCommand(""+timestampString)
  if(cameraGaragePrevMotion < timestampEpoch){
    logInfo("cameraGarageLastRecording","Motion Garage")
    cameraGaragePrevMotion = timestampEpoch
    
    // If you prefer to just get notification
    //sendBroadcastNotification("Kamera Garage")
   
   // Pushover notification with attachments 
   cameraGarageSnapshot.sendCommand(ON)
    createTimer(now.plusSeconds(1),  [ |
      val actions = getActions("pushover", "pushover:pushover-account:account")
      // send attachment message
      actions.sendAttachmentMessage("Camera Garage", "Garage", "/tmp/garage.jpg", "image/jpeg")
    ])
  }

end

rule "cameraGarageMotionState"
when
	Item cameraGarageMotionState received update
then
  if(cameraGarageMotionState.state == "true"){
    motionCameraGarage.sendCommand("ON");
  } else {
    motionCameraGarage.sendCommand("OFF");
  }

end

rule "cameraGarageMotionChangeState"
when
	Item motionCameraGarage received update
then
  var preStateChangeContent='{"name": "Garage","recordingSettings": {"fullTimeRecordEnabled": false,"motionRecordEnabled":'
  var postStateChangeContent=',"channel": 0 }}'
  var httpUrl='http://<unifi video server>:7080/api/2.0/camera/<camera id>?apiKey=<API key>'

  if(motionCameraGarage.state == ON){
    sendHttpPutRequest(httpUrl, "application/json", preStateChangeContent+'true'+postStateChangeContent)
  } else {
    sendHttpPutRequest(httpUrl, "application/json", preStateChangeContent+'false'+postStateChangeContent)
  }

end

sitemap

Frame label="Cameras" {
          Text item=cameraGarage valuecolor=[CONNECTED="green",DISCONNECTED="red"]
          Text item=cameraGarageLast
          Switch item=motionCameraGarage
          Image url="http://<unifi video server>:7080/api/2.0/snapshot/camera/<camera id>?apiKey=<API key>&width=500&force=true&t=1516046678" refresh=10000

}