MQTT remote control of UI3 instances

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,666
Reaction score
14,007
Location
USA
Over the years, several people have asked for ways to remotely control UI3 instances beyond what is enabled by URL parameters. I always had to say there is no easy mechanism for this to happen. But I recently learned that most popular MQTT brokers make MQTT accessible via web socket. So I should be able to get UI3 to connect to an MQTT broker and use it as a data channel for remote control.

I'm not really the target audience for such a feature, so if anyone could provide comments on how it should work, that would be appreciated. I created an issue on github but I can also read replies to this thread.
 

The Automation Guy

Known around here
Joined
Feb 7, 2019
Messages
1,377
Reaction score
2,738
Location
USA
This will be great!

At first I couldn't think of a use case, but then I realized that being able to pull up a specific camera feed based on a specific MQTT event would be really helpful. I know you can currently set the GUI to automatically pull up a camera that has been "triggered" in BI, but this feature would take that and expand it to events outside of the BI triggering system. Doorbell rings, a door being opened, an alarm system's motion detector, a light being turned on/off, weather conditions, time of day, dawn/dusk, etc, etc, could all be used to trigger a specific GUI/camera view(s).

Along with that line of thinking, it would probably be best if you include a "reset" time option on these MQTT triggers as well. So just as a BI triggered camera view will reset and go back to the default view after a period of time, a user would probably want the same option available on the MQTT triggers. But they might also want the GUI change to be "permanent" and not reset after a period of time depending on the situation. Is it possible to allow both options? IE have one command for a GUI change with a timed reset back to the default view and another command for a "permanent" GUI change that doesn't reset. Or maybe it's a single command with a milisecond delay time element included and if the ms is set to 0 it doesn't reset back to the previous view.

I also assume each instance of UI3 would be able to be controlled separately via its IP address? So if you wanted one device to change to a specific camera feed when triggered by a MQTT event, but not other devices, that is a trivial thing to accomplish? Would there be a way to change all instances of UI3 at the same time?
 
Last edited:

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,666
Reaction score
14,007
Location
USA
At first I couldn't think of a use case, but then I realized that being able to pull up a specific camera feed based on a specific MQTT event would be really helpful. I know you can currently set the GUI to automatically pull up a camera that has been "triggered" in BI, but this feature would take that and expand it to events outside of the BI triggering system. Doorbell rings, a door being opened, an alarm system's motion detector, a light being turned on/off, weather conditions, time of day, dawn/dusk, etc, etc, could all be used to trigger a specific GUI/camera view(s).
I'm not sure I'm understanding your intent exactly, but I do not think it should be UI3's job to accept programming from the user to make UI3 subscribe to arbitrary MQTT topics and look for specific values to do specific things. Say I create a system where you can program simple event handlers, e.g. IF MQTT topic Doorbell/Ringing IS 1 THEN Open Live Camera frontporch AND Set Volume to 100. Then it needs an optional delayed reset mechanism like you also mentioned, but there are a lot of related situations that need to be handled. E.g. what happens if, before the reset, the same condition gets met again, or another MQTT condition gets triggered, or a user interacts with the UI directly, etc. Now the simple event handler is not simple anymore. I really don't want to deal with all of that. Better that those decisions are made in a home automation controller like Home Assistant I think, since it should have way more powerful automation capabilities than I would ever be willing to code into UI3. Admittedly Home Assistant's complexity is very high because of it. I suspect it would be necessary for someone to create a UI3 integration/addon for Home Assistant. I am not really interested in taking it that far myself. No need for a UI3 integration/addon in Home Assistant since it can already do an action of type Call service with Service MQTT: Publish and it could therefore control UI3 that way.

See, my original plan was to have UI3 publish certain values from its current UI state to a number of MQTT topics, and also subscribe to those same topics so that other MQTT clients can publish values to them to change the state of the UI3 instance.

Example: All cameras, video player maximized, volume muted:

UI3/instance_id/state/cam -> index
UI3/instance_id/state/maximize -> 1
UI3/instance_id/state/volume -> 0

I'd probably add a couple of other settings (streaming quality perhaps?) but those 3 MQTT topics above would be the most useful I think.

The instance_id would be randomly generated and saved in settings so it would be persistent, but also manually settable so you wouldn't be forced to use the randomly-generated instance ID and you could even have multiple devices share the same instance ID so they would both mirror each other. And consequently they would both remotely control each other right out of the box if you connected them to the same MQTT broker and gave them the same instance ID.

I also assume each instance of UI3 would be able to be controlled separately via its IP address?
Yes and no. The control would not be based on IP (that would be poorly suited for many reasons actually). Instead it would be based on an instance_id as I described above.

So if you wanted one device to change to a specific camera feed when triggered by a MQTT event, but not other devices, that is a trivial thing to accomplish? Would there be a way to change all instances of UI3 at the same time?
Yes to both.
 
Last edited:

The Automation Guy

Known around here
Joined
Feb 7, 2019
Messages
1,377
Reaction score
2,738
Location
USA
I'm not sure I'm understanding your intent exactly, but I do not think it should be UI3's job to accept programming from the user to make UI3 subscribe to arbitrary MQTT topics and look for specific values to do specific things. Say I create a system where you can program simple event handlers, e.g. IF MQTT topic Doorbell/Ringing IS 1 THEN Open Live Camera frontporch AND Set Volume to 100. Then it needs an optional delayed reset mechanism like you also mentioned, but there are a lot of related situations that need to be handled. E.g. what happens if, before the reset, the same condition gets met again, or another MQTT condition gets triggered, or a user interacts with the UI directly, etc. Now the simple event handler is not simple anymore. I really don't want to deal with all of that. Better that those decisions are made in a home automation controller like Home Assistant I think, since it should have way more powerful automation capabilities than I would ever be willing to code into UI3. Admittedly Home Assistant's complexity is very high because of it. I suspect it would be necessary for someone to create a UI3 integration/addon for Home Assistant. I am not really interested in taking it that far myself. No need for a UI3 integration/addon in Home Assistant since it can already do an action of type Call service with Service MQTT: Publish and it could therefore control UI3 that way.
I agree that the mechanics behind the logic that I was referring to should be handled by some sort of separate automation system. It was not my intent to suggest that you should build this out.

I guess I was most excited about the possibility to give a command that would change the current view to a specific camera or group. Perhaps this is already possible through the different URL parameters (honestly I have not really though about any of this prior to your OP, so I have never looked into it) or perhaps this is might be accomplished through your first parameter "cam" in your example. I had not thought about it before, but I can definitely see where turning the audio on/off and maximizing the screen would also be helpful parameters to be able to control.

For example, I can see a scenario where a severe weather alert comes into a larger automation system. Based on that event, the larger automation system might have logic built in to change all of the UI3 instances to show a particular outdoor camera that faces to the West (and therefore the likely direction of any impending severe weather). It would do this by sending the MQTT command UI3/instance_id/state/cam -> West_Camera to use your example (hopefully correctly).

Again, the only thing I'm hoping for is the mechanism to send a command to change the UI3 current view to a specific camera/group either by a URL command or a MQTT command. Everything else (all the logic) would be handled by something else. If I understand your last post correctly, this is what you are planning to expose.
 
Last edited:

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,666
Reaction score
14,007
Location
USA
Yeah. So far the only ways to automate UI3 has been through:
1) Changing the URL and reloading the page (this could be used to switch cameras, but its janky)
2) Programmatically moving the mouse, clicking, or pressing hotkeys.
3) UI3 local overrides javascript could technically be used to do anything, but that is really difficult and rarely used.
 

thanatar

n3wb
Joined
May 27, 2019
Messages
2
Reaction score
1
Location
Here
Would it be possible to add a way to have the playback stop on the player? My use case is I have a few monitors that we view the cameras on connected to raspberry pi's. They have Kodi loaded on them currently and I pull in the RTSP stream directly. When we stop playback the screensaver kicks in turning off the monitor. I would reload them with raspbian and use the chromium browser if I can get this part to work as it would let me view more than one camera at a time.
 

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,666
Reaction score
14,007
Location
USA
Hey @thanatar, I'd be happy to add that for you. But first, can you confirm if pausing the live video (space bar keypress should achieve that) is sufficient to allow the screensaver to activate?
 

thanatar

n3wb
Joined
May 27, 2019
Messages
2
Reaction score
1
Location
Here
Hey @thanatar, I'd be happy to add that for you. But first, can you confirm if pausing the live video (space bar keypress should achieve that) is sufficient to allow the screensaver to activate?
Tested this today. It does indeed allow the screen to turn off when the video stream is paused and turns back on when the space bar is pressed. Let me know if you need me to test anything else.
 

DLONG2

Known around here
Joined
May 17, 2017
Messages
763
Reaction score
454
Granted I am pretty weak on this MQTT stuff, but I'm trying to understand how a home automation event would make a specific instance of UI3 behave? Does the command affect any and all views of UI3 which might be in service at the same time?
 

hikky_b

Pulling my weight
Joined
Nov 24, 2019
Messages
156
Reaction score
168
Location
London
Granted I am pretty weak on this MQTT stuff, but I'm trying to understand how a home automation event would make a specific instance of UI3 behave? Does the command affect any and all views of UI3 which might be in service at the same time?
UI3 will give each instance a unique ID (you can also specify the ID) that you can then subscribe/publish to. So when publishing your MQTT command you can specify which device/instances you want to affect. Alternatively you can set the ID to be the same on multiple devices and control them all together.

e.g:

Individual Control:

iPad:
ui3/kitchenipad/state/vid
TV: ui3/familytv/state/vid
Office PC: ui3/officepc/state/vid

OR

Controlling all together:

iPad:
ui3/myhomeui3/state/vid
TV: ui3/myhomeui3/state/vid
Office PC: ui3/myhomeui3/state/vid
 
Top