Subscribe to log?

Was wondering if there was any way to subscribe (or any other means) to the log? Was hoping to create something I miss from Homeseer. There is a app that looks at the log and reports based on keywords. Things like error or warn. Custom phrases too.

I know we can look at individual device logs but what about the full log - 'Logs'?

Any ideas?

Thanks

You could connect to the log socket and parse the messages that appear there. It is a websocket connection. The URL is:

ws://hubip/logsocket

Thanks @dan.t, I also found your code from this post. I modified it to use the current way HE handles websocket but it won't connect. Any ideas what I'm doing wrong? Thanks

(using the latest Chrome browser on a Chromebook beta channel)

// Test webSocket Driver

metadata {
	definition (name: "webSocket", namespace: "BPTWorld", author: "Bryan Turcotte", importUrl: "") {
   		capability "Actuator"
        
        attribute "status", "string"
        
        command "connect"
        command "close"
    }
}

def connect() {
	interfaces.webSocket.connect("ws://192.168.7.91/logsocket")
}

def close() {
    interfaces.webSocket.close()
}

def webSocketStatus(String socketStatus) {
	if(socketStatus.startsWith("status: open")) {
		log.info "Connected"
        sendEvent(name: "status", value: "Open", displayed: true)
		return
	} 
	else if(socketStatus.startsWith("status: closing")) {
		log.info "Closing connection"
        sendEvent(name: "status", value: "Closing", displayed: true)
		return
	} 
	else if(socketStatus.startsWith("failure:")) {
		log.warn "Connection has failed with error [${socketStatus}]."
        sendEvent(name: "status", value: "Failed", displayed: true)
	} 
	else {
		log.warn "Connection to has been lost due to an unknown error"
        sendEvent(name: "status", value: "Lost", displayed: true)
	}
}

def parse(String description) {
	log.debug "Got Data ${description}"
}

But get this in the log:

dev:57582019-08-31 07:50:30.812 am warnConnection has failed with error [failure: Failed to connect to /192.168.7.91:80].

Try a different port.

1 Like

Does HE use a specific port for websockets? I didn't see that in any of the posts or docs.

I believe there is a specific port for the event socket. I'll search around and see if I can find it.

Holy crap, I put in 8080 as a wild guess and it connected!

Thank you!

edit:
Seeing great data in the log to:

dev:57582019-08-31 08:01:23.424 am debugGot Data {"name":"Living Room Shelf Multisensor","msg":"Living Room Shelf Multisensor motion is inactive","id":98,"time":"2019-08-31 08:01:17.713","type":"dev","level":"info"}

dev:57582019-08-31 08:01:23.415 am debugGot Data {"name":"Test","msg":"In motionSensorHandler (v2.0.0) - sZone: true - Status: inactive","id":7371,"time":"2019-08-31 08:01:12.437","type":"app","level":"debug"}

dev:57582019-08-31 08:01:23.406 am debugGot Data {"name":"Living Room Iris Motion Sensor","msg":"Living Room Iris Motion Sensor is inactive","id":1567,"time":"2019-08-31 08:01:12.260","type":"dev","level":"info"}

dev:57582019-08-31 08:01:23.398 am debugGot Data {"name":"aWeb socket","msg":"Got Data {"name":"aWeb socket","msg":"Got Data {"name":"Kitchen Iris Motion Sensor","msg":"Kitchen Iris Motion Sensor is inactive","id":1589,"time":"2019-08-31

1 Like

This is what people are using to log there data. Seems pretty solid from what I've read.

You can connect to the standard port 80 to get the logs if you come from a different device like a raspberry PI or so. If you do it from within HE, you need to connect to port 8080. It has to do with how the core HE SW listens to ports. You could have also tried to connect to ws://localhost/logsocket , that might have worked to. This way you don't have an IP address in the device code and make it easier to share with others. Just a thought...

Just tried it.

ws://localhost:8080/logsocket works, you have to have the port

That makes sense, thanks

I'm already parsing out data on keywords like 'error' or 'motion'. This is going to be very useful!

Time to have some fun, lol.

Just be careful about what you log from your app! Otherwise you will log again what your app logs and you cause a recursive logging.

yup, already did that once, lol.

Sending data to the attribute now :grin:

1 Like