EZ-HouseMode-SceneRunner

EZ-HouseMode-SceneRunner

Continuous IntegrationDocker to ghcr.io

Easy (EZ) Node.js app that runs a scene on Ezlo Hub(s) whenever the hub transitions to a new House Mode. For convenience, the app is deployed as a dockerized app for Intel/AMD and ARM platforms.

Motivation

This EZ-App illustrates the simplicity of using Ezlo-Hub-Kit to discover hubs, register observers to asynchronously act on House Mode changes and execute scenes on Ezlo Hubs. This EZ-App will appeal to Vera Users who have grown accustomed to employing scenes triggered by House Mode changes because, as of this writing, Ezlo Hub scenes can not use House Mode changes as a trigger. EZ-HouseMode-SceneRunner bridges this obvious gap until Ezlo implements the feature to trigger scenes by a House Mode change.

How it works

Easy HouseMode-SceneRunner registers House Mode change observers for each hub that it discovers on the local network. Because Ezlo Hubs default to waiting 30 seconds to change to House Modes “Night”, “Away” and “Vacation”, it demonstrates how to use multiple hub observers. One Observer triggers when a hub starts to change House Modes and one another Observer triggers when the hub completes the House Mode change. The former is simply used to log the fact that a hub has initiated a house mode change and the later is used to execute a scene for that mode. For convenience, EZ-HouseMode-SceneRunner includes a default scene map but users are able to override it by providing a custom map as a JSON file that maps a scene to a scene name. EZ-HouseMode-SceneRunner is intentionally limited to using a single scene name for each mode, meaning that multible Ezlo hubs need to use the same scene name for a given mode (e.g. Home => Return, Night => Sleep, Away => Leave, etc.).

Usage

  1. Start the dockerized EZ-HouseMode-SceneRunner app
$ docker run -it --network host \
             --name ez-mode-scenerunner \
             -e miosUser=<MIOS Portal User> \
             -e miosPassword=<MIOS Password> \
             ghcr.io/bblacey/ez-housemode-scenerunner
  1. Verify that the application starts successfully, discovers the local Ezlo hubs and acts upon Ezlo hub House Mode changes. You can verify the behavior by changing the House Mode on one or more of your Ezlo Hubs.

The log snippet below shows the Easy HouseMode-SceneRunner app starting, reporting the discovered Ezlo Hubs and executing a scene for a given mode change. For this case, the mode was changed to Night on the Vera that the compainion app EZ-HouseMode-Synchronizer propogated to each Ezlo Hub which in turn was detected by EZ-HouseMode-SceneRunner to run the appropriate scene, if the named scene for the transition mode exists on the hub.

Using scene map
{
  "1": "Return",
  "2": "Leave",
  "3": "Sleep",
  "4": "Vacation"
}
Managing HouseMode Scenes for: 92000014, architecture: armv7l	, model: h2_secure.1	, firmware: 2.0.7.1313.16, uptime: 3d 8h 1m 57s
Managing HouseMode Scenes for: 90000369, architecture: armv7l	, model: h2.1	, firmware: 2.0.7.1313.16, uptime: 1d 19h 12m 22s
Managing HouseMode Scenes for: 90000330, architecture: armv7l	, model: h2.1	, firmware: 2.0.7.1313.16, uptime: 3d 22h 23m 28s
Managing HouseMode Scenes for: 70060017, architecture: esp32	, model: ATOM32	, firmware: 0.8.528, uptime: 3d 23h 39m 47s
Managing HouseMode Scenes for: 76002425, architecture: esp32	, model: ATOM32	, firmware: 0.8.528, uptime: 0d 21h 39m 17s
Managing HouseMode Scenes for: 70060095, architecture: esp32	, model: ATOM32	, firmware: 0.8.528, uptime: 0d 9h 8m 15s
+ Ezlo 90000369: Changing from House mode 1 to mode 3 in 10 seconds
+ Ezlo 92000014: Changing from House mode 1 to mode 3 in 30 seconds
+ Ezlo 90000330: Changing from House mode 1 to mode 3 in 1 seconds
+ Ezlo 70060017: Changing from House mode 1 to mode 3 in 20 seconds
+ Ezlo 76002425: Changing from House mode 1 to mode 3 in 30 seconds
+ Ezlo 70060095: Changing from House mode 1 to mode 3 in 1 seconds
+ Ezlo 90000330: Changing from House mode 1 to mode 3 in 0 seconds
- Ezlo 90000330: Transitioned to House Mode 3.  "Sleep" scene in context.
+ Ezlo 70060095: Changing from House mode 1 to mode 3 in 0 seconds
- Ezlo 70060095: Transitioned to House Mode 3.  "Sleep" scene in context.
➔ Ezlo 70060095: Executing scene Sleep:scene_679E756306322DFC
✓ Ezlo 70060095: Sleep scene finished
+ Ezlo 90000369: Changing from House mode 1 to mode 3 in 0 seconds
- Ezlo 90000369: Transitioned to House Mode 3.  "Sleep" scene in context.
+ Ezlo 70060017: Changing from House mode 1 to mode 3 in 0 seconds
- Ezlo 70060017: Transitioned to House Mode 3.  "Sleep" scene in context.
+ Ezlo 92000014: Changing from House mode 1 to mode 3 in 0 seconds
- Ezlo 92000014: Transitioned to House Mode 3.  "Sleep" scene in context.
+ Ezlo 76002425: Changing from House mode 1 to mode 3 in 0 seconds
- Ezlo 76002425: Transitioned to House Mode 3.  "Sleep" scene in context.

There are a few take-aways from the log snippet above. First, six hubs are discovered. Second, several hubs are configured with a different scene transition time that EZ-HouseMode-SceneRunner reports when it detects that a hub is starting the transition to a new mode. Third, only one of the six hubs (hub 70060095) has a scene named “Sleep” mapped to the Night House Mode so only that hub was instructed to execute the Sleep scene. Finally, the hubs complete their house mode transition in ascending “switch-delay” order even though they initiated the mode change in reverse order - this demonstrates Ezlo-Hub-Kit waiting for a hub to acknowlege a successful transition that clients can use to trigger the next step which in this case, is executing a scene. Each of the events happens asynchronously as a result of a hub broadcasting updates in response to actions.

Scene Map

The default scene map provides general scene names for each house mode. EZ-HouseMode-SceneRunner will execute the named scene when a hub transitions to a new mode if that scene name exists on the hub. So, if a user wants all their hubs to run a scene whenever they return home, they can either create a “Return” scene on each hub or create a custom name and provide a custom scene map to the app.

{
  "1": "Return",
  "2": "Leave",
  "3": "Sleep",
  "4": "Vacation"
}

For example, if a user wanted the scene that is run their hubs transition to Night Mode (3) to be call “Boo-yah”, they would create a file with the contents above and change the name to “Boo-yah” for the corresponding mode.

To pass the custom scene map to the app, the user will either specify it when running docker run or include it in the docker-compose file. For example:

docker run "sceneMap=$(<scene-map.json)" ...

Production use

To run the dockerized Easy House-Mode-Synchronizer as a persistent process you can use docker-compose (recommended) or run the docker container ‘detached’ as a background process.

First, for either option, create or download config.env and edit the file to to use your MIOS portal username and password.

docker-compose (recommended)

For those users who prefer to use docker-compose, you can download the docker-compose.yml and start the relay with.

docker-compose up -d .

Compose users may find the EZ-Apps github project useful. It comprises a docker-compose file with unified config files need to run the EZ-App suite with a simple docker-compose up -d.

docker run --detatch (alternative)

Start the relay in detached mode.

$ docker run --detach --network host \
             --name ez-mode-sync \
             --env-file config.env \
             ghcr.io/bblacey/ez-housemode-synchronizer

Head over to the EZ-HouseMode-SceneRunner Github repo to get started!

2 Likes

On Vera many years ago, I setup four scenes for the different House modes and just had those scenes call the correct House Mode change via a line of Lua code.

So I run my “Home” “Away” “Night” and “Vacation” scenes to change the house modes and also perform my other required actions within the scene etc. I don’t actually use the house modes themselves directly.

So this EZ-HouseMode-SceneRunner app is the other way round, the house mode change calls the appropriate scene, which makes more sense.

So this EZ-HouseMode-SceneRunner app has to be hosted and run on a separate machine outside of the Ezlo hub right?

Maybe on a Raspberry Pi running Docker Compose.

I know this is an example app etc, but it would be nice to have this functionality baked right in to the Ezlo hub itself. So when the house mode changes you can easily specify a scene to run at that time also.

Precisely. I, and I’m sure others here, will be happy to help you along with that. You will need something like an RPI for Reactor Multi System too.

Ezlo is planning to add “scene blocks” at some point but it just isn’t there yet so you can’t configure a scene to trigger on a house mode change. That is was this EZ-App does. The example Apps are meant to be used for people making the transition and by developers to understand the Ezlo-Hub-Kit SDK - I’m using all three EZ-Apps in my home and have been for some time now.

Yes I gathered as much. I do have an older Raspberry Pi 2 running Node-Red and HA Bridge currently.

I also tried to run InfluxDB and Grafana on it, which I did manage to get setup and working with the VeraFlux plugin, but the little Pi couldn’t cope with the over head of it all logging everything in realtime it just killed the resources on the Pi, so I had to disable it all.

I may have to invest in a newer Raspberry Pi 4 for running all that and also for Reactor Multi System and maybe MQTT if I start getting in to that, as I’ve never used it so far.

Maybe even a newer Pi can’t cope with InfluxDB and Grafana though ?

I might have a go at this HouseMode-SceneRunner see if I can set it up on my current Pi?

I’ve never used Docker either so all a bit new to me.

Thanks.

It would probably able to handle everything but the problem with InfluxDB is that it hammers the SDRAM card. You can setup a PI to boot from a different media like SSD and then it could handle pretty much anything you throw at it.

Well, if it were me, I would install docker and use it for HA-Bridge, Node-Red, MQTT and HouseMode-SceneRunner in their own containers. But, if you already have Node-Red running, then you probably have what you need for Ezlo-HouseMode-SceneRunner without docker.

To do so, on your PI, either download the ez-housemode-scenerunner repo using GitHub’s download, or git clone it. Then “cd” into the ez-housemode-scenerunner/node-app directory and run npm install to install the EZ-App dependencies. Then, set the environment variables in config.env and finally run node index.js to start the app. If that sounds like too much, then I would bone up on docker, get it running and just use the docker image as described in the ez-housemode-scenerunner readme.

Here is a pretty good how-to for installing docker on an RPI - Docker on Raspberry Pi - Installation Guide | phoenixNAP KB

1 Like

On second thought, if you want to experiment with Docker in an ease-in approach, there are some steps you can take immediately without impacting any of you existing systems.

  1. You can work through the “Play with Docker” cloud-based docker tutorials here. This will help you familiarize yourself with docker, the basic commands, etc.

  2. If you don’t want to rock your RPI2 right now, you can install Docker Desktop on Windows & macOS. That might provide a more-approachable next-step playground where you can experiment with the actual EZ-Apps in the near term. The nice thing about Docker is that any app/image that you install is non-intrusive/destructive to your primary system because everything runs in a self-contained container that you can start, stop and delete with one-line commands.

I’m confident that you will really appreciate docker once you climb the learning curve and you seem to enjoy the mind-candy this new arena will offer. Furthermore, I know you are interested in @rigpapa’s Reactor MultiSystem so this will help you get Docker up and running so you can easily spin-up Reactor MultiSensor when the time comes.

And not to fear, there are plenty of docker users here to help if you want to give it a whirl.

Just get a mini pc with ssd. I started with a PI, moved to a celeron mini pc and now I have an intel i3 with 16 gb ram and 512 gb ssd running Linux server. I got it from work, when they swapped desktops with laptops and even if it’s 3 years old, it’s rock solid. It’s a mini pc, so smaller than my vera plus, but it’s able to run whatever you want. I’m sure there are used ones on eBay and usually it’s about 200 eur new, where a pi with ssd and a case is usually 100+.

Which Linux distribution are you using?

Ubuntu, because I like it. No problems with drivers, I got Bluetooth working too, so I integrated a couple of bt only devices.

1 Like

Agreed, you might as well skip right over the Pi if there is a chance that would be your end step. I have a couple old Mac Minis running Ubuntu Linux and like @therealdb said, it supports pretty much any hardware. Both make heave use of docker and one sits within an isolated VLAN with a Vera Edge running Ezlo Linux for automated Ezlo-Hub-Kit regression tests). You can’t go wrong with the real deal, especially if you do want to run InfluxDB.

SIGH I wish the house modes plugin was baked into the new Ezlo firmware. I used it on my old Vera secure to run scenes whenever the house mode changed. Hopefully that will be added soon.

Hello @rlargent,
At the moment, you can change the house mode with an action in the scenes. Unfortunately, you can’t trigger scenes with the change in the house modes. However, you can create a scene that changes the house mode along with other actions and run it every time you need to change the house mode.
Also, you can use our Community Feature and Bug Tracker tool to send a feature request for this idea. More information on this tool can be found here.
Regards!

That’s how I have always done it on my Vera hub.

I have scenes that change the house mode and then run other actions as well.

I never change the house modes directly.

That doesn’t work very well when using a keypad though. I was hopeful that one of the virtual sensors available would allow me to make a status update through the house mode configuration that I could use to trigger a scene. The only one I see is the motion sensor and I don’t think it will work. Oh well I’ll keep trying to get creative and maybe I’ll come up with something. On my Vera Secure I was able to use the house mode plugin to trigger a voice monkey to announce whenever the scene changed via Alexa and turn on/off lights depending on the mode. For example I would turn on the porch lights for 10 minutes if it was after dark when changing to home mode. It doesn’t seem like much but was nice when coming home after dark to just have everything do what I needed when just disarming the system. Maybe this ability will get implemented soon. I love the responsiveness of the new system but am playing with the ideas of keeping the new, going back to the old, or getting rid of automation completely and returning the house to dumb switches and outlets.

Seems like a good idea to be able to trigger a scene when the house mode state changes from one mode to another.

Was a feature request made?

Yes I did make a feature request a couple weeks ago (ECS-747).
I don’t think it has been assigned or reviewed since the status still says “open”.

All mine say open and I have like 80 tickets. :blush:

I have asked them to bump your ticket up the list.

That’s great. Thank you for the report. Here is the link to the request in case anyone else wants to take a look Log in - MiOS.
In the meantime, you could create the scenes that trigger manually and run them from the app or with voice commands to Alexa.
Regards!

That is fantastic! thanks

1 Like

Ok so I decided to give this a try.
Once I have everything setup and running in a docker container I am seeing the site map but it doesn’t appear to discover my hub. I must be missing something but can’t seem to figure out what. Any suggestions? I’m thinking maybe username and password are wrong. Is this the same username and password used to login to the Ezlo Hub?