Source Selection Using Reactbrowsing

Tomorrow I am planning to embark on the journey with Dash React. I am rebuilding my system from scratch. As I work through it I will post some screen shots and hopefully some good tips. I guess I should address the topic. LOL. I am planning to start out the journey with source selection. So instead of string variables, I am going to use the new React module to select sources.

My belief is that as a group we will begin to adopt new ways and find new fun and interesting ways to handle tasks that we want to accomplish. It's open-ended so I think it will be cool to see what we come up with!

This is my first attempt. This attempt is wrong. I have posted the How To further down the page with the correct procedures. My intention for this post was to document how I started, where I went wrong, and how it ended up working.

Attempt one. I am struggling with the each source. Do I need to create an event for each source available? As I am typing this, I think I am getting it. LOL. Okay, let me try this.

So, first create an event with the variable for watch living room source.

This will be used for all sources.

Second create events for each source. These will be used by all rooms that have access to the source.

Here I am creating an event for DirecTV.

Now, we will create the actual trigger. This will be a TCL command in the Living Room Macro for DirecTV

I probably messed this all up, but I gave it a shot. I didn't put in commands in the actual events, I believe those are will be the commands that should occur when that event happens.

Can you clarify or show a full example of turning a room source on and all it's components? I am struggling with the each source. Do I need to create an event for each source available? As I am typing this, I think I am getting it. LOL. Okay, let me try this.

So, first create an event with the variable for watch living room source.

So what you've done here is created a macro that will trigger whenever the "LivingRoomSource" macro includes "Watch" - this is a macro where you would probably turn on the TV and set the HDMI Input (unless using multiple inputs on the TV).

This will be used for all sources.

This is actually correct, whenever you are "Watching" a source you will add "Watch" to your LivingRoomSource Variable and can be confident the TV will be on if programmed as specified above.

Second create events for each source. These will be used by all rooms that have access to the source.

Here I am creating an event for DirecTV.

While you could probably make something like this work, I think you are thinking about it backwards. Your variable name should still be LivingRoomSource and becomes operator should be "Includes" "DTV1" or "DirecTV1" (whichever you prefer). This means you would set your LivingRoomSource variable to Watch-DTV1 or Watch-DirecTV1 to trigger the commands

As this stands you have two variables, one called LivingRoomSource and another called DirecTV1 - both of the macros you have created are set to trigger when their values include Watch.

Now, we will create the actual trigger. This will be a TCL command in the Living Room Macro for DirecTV

I probably messed this all up, but I gave it a shot. I didn't put in commands in the actual events, I believe those are will be the commands that should occur when that event happens.

That trigger would not work but you are close, just modify the second event as shown and you should be good

Ok, so I got it to work. I made two mistakes, well 4. Brady caught one, see post above. After discussing with Brady it seems that the better option (well he may change his mind, so for now we will call it the option that offers the greatest flexibility) for source selection is to build events for every source for each room.

So, in doing that I made a second mistake. I changed the "Becomes Logic Options", for me it made sense that when the "statement becomes true", do x. That isn't the case, leaving it as the default "statement becomes true and remains true" is the correct method.

My third mistake was using spaces in the value field. This has been updated now, I believe spaces are now allowed. So after fixing those, the set source worked.

And it is fast. It fired everything on at one time. Crazy fast.

Then the 4th mistake. I put the command for Off in the Room On field. LOL. So...I fixed that.

One of the nice things about this is the simplicity. Because the actions are compartmentalized it is easy to troubleshoot and to understand what the action is doing. I find it easier to understand when compared to the string variable method. Also seems like less chance for programming errors.

Stay tuned until tomorrow, I will post a short "how to" with screen shots and do my best to explain how and why each step works.

Quick question...
If all events fire at the same time how do you get round the problem of source switching with devices that take a while to come on?
For example - My Anthem AVR will not respond to commands for 7 seconds while powering on. With string variables I can control when the input commands are sent by the order of the macro and delays, with event variables I can't. Or can I?
Just re-programming my home system to try and get my head round React and this is the first thing I thought of.

Absolutely you can. That is the beauty of this. The separate commands all run at the same time in the background. I am driving right now. When I get a moment, this afternoon, I will post the screenshots and walk through.

As usual you can expect there to be quite a few responses to any questions you may pose. However you are right that these types of things will likely be the biggest challenge for people. There are a few powerful methods you can use to accomplish your goals. However, it's positive to see that you guys are thinking about these things as these are the biggest hurdles dealers are going to run into... luckily the solutions are fairly simple!

Regardless of the option we choose, keep in mind that React will still provide the end-user with an "instantly ready" experience as it will all trigger in the background, but we will simply run less simultaneously.

So we are already assuming when we want to set a source, lets say Roku, we will be setting our variable to the following:

Watch-Roku

Now depending on how we have the system setup we will decide what each function does, and when it gets triggered. The obvious answer here is to have the following rules setup:

IF $Bedroom (INCLUDES) Watch
IF $Bedroom (INCLUDES) Roku

So when setting our variable Bedroom to the value listed above, we would have two macros fire, one for "Watch" and one for "Roku." This also means we will have two simultaneous macro operations (each of the said macros). Our goal is to "compartmentalize" the functions of our systems into simple, easy to understand and modify re-useable snippets. Once we have done this, we will be able to manipulate our systems and execute more and more advanced functionality without the fear of missing a step in the programming, etc because we are always using the same snippets which we have confirmed as working.

We get to decide what each function does and how it should React. Well if we consider our other variable values might look like this:

Whenever Watch is apart of our variable we know that at the very minimum the TV needs to be on. Since this runs in the background, we don't have to worry about adding delays, etc. so we can put something like "TV ON" "DELAY 7 SECONDS" "HDMI 1" and the user will never need to even know the delay occurred. We can also possibly safely assume that the AVR will need to be turned on and switched to the proper source so we will have a couple options in front of us here.

We can simply turn on the Receiver and provide the proper delays on the "Roku", "DVD", "Cable", etc part of our macro. Keep in mind your macros are still in the background so any delays your end-user won't perceive other than waiting for the actual thing to switch - their UI will already be switched for them giving them a sense that the system is much more responsive.

We can Turn on the AVR from the "Watch" macro (so that it only ever needs to be in one place). When we do this, if we decide to do the source switching in the "Roku", "Cable", etc part of our macro then we do need to consider how best to handle it to make sure the command will work as designed.

Option 1: Source Delays

We could build in a simple delay. Since this macro runs in the background it shouldn't cause any problems to do something like so:

In the above example we are instantly setting the AVR to the Roku input, but then providing a small delay (or whatever may be necessary) and then sending the command again. Since this runs in the background without freezing up the end-users UI this won't be a problem as if the AVR was already on the switch will be immediate, otherwise it will take the normal amount of time. Without any IF/ELSE Statements we have still accomplished our goal in just a few lines.

Option 2: URC Variable Abstraction

While this won't make as much sense in this situation, another option when we run into complexities that we aren't sure how best to build Asynchronously, we can abstract from the React Methods and return to what we are used to. This would involve us running a GET VARIABLE VALUE Command on our variable from within the Watch side of our macro then using URC's Standard String Variable approach as we have been doing. We will have multiple macros running simultaneously so other things are going on as-needed. In significantly more complex situations there are times this may make a lot of sense to do as it provides a bit more ordered structure to your macro:

Once we send this command, our URC String Variable will have a value of "Watch-Roku" (or whatever we set it to). We can then run any kind of URC Command against it simple enough:

Option 3: Callbacks & Triggers

Ok so this is technically going to be the most reliable method of doing this type of thing when the situation becomes more complex - and it is extremely powerful. However, I am not going to go very deep into it (mainly because I have to play with various ways of doing this since there are probably 100 to figure out what the best is). Here is the basic idea/concept:

When we build our commands, we can "append" data to the variable which will then react with macros triggering.

When our Receiver has finished turning on, we can "Append" a parameter to our variable letting React know it's ready for commands.

When our new parameter is included in the macro, we can then send the proper input switch commands - we can use In-Event Logic ("If $Bedroom (INCLUDES) Roku AND AVRReady") or we can grab the variable value as shown above and check if it includes our "Ready" parameter (AVRReady).

However, this option is definitely overkill for something like the AVR dilemma originally proposed. I wouldn't go this deep for something like that unless you are just doing it to learn and play with the React Toolchain or if you have a significantly more complex desire.

Cloud Logging!

Don't forget to add lots of Output to Cloud Logs while you are programming rather than waiting until you need it. This way your logs will make more sense as you know exactly what you are expecting to happen and where. You will need to do this less and less as you move on and start building your standard ways of doing things, but for now I can't recommend using it more than usual so you can see what is happening and why/when.

Just setting up our demo system with React and I have everything switching on and off as it should, however, I cannot get room tracking to work.
The devices will switch on and the UI will jump to the correct interface but after 30 seconds it drops back to the main page.

I know this has something to do with device power on and offs but don't know how to implement it with React.

EDIT: The room tracking isn't working 'cause none of my React events are happening. Something has gone very wrong

FYI The term React comes from the user setting the variable and the system reacting to the variable that was set.

Below are the screen shots of a simple source on and off. What this is going to do is to set up the Living Room and tune to Apple TV. I am doing it in 3 steps. Step 4 will be turning the room off.

Step One. Create the device event for Living Room Source Watch. This will set up the room for what ever source you are going to watch. In this example, the TV is turned on, the matrix is turned on and the receiver is turned on.

Step Two. Create the device event for the source selection for Apple TV. This will trigger when the value is seen (step three). In this event the commands for selecting the source are inserted. You will notice in the Device Events tree that I create similar events for all sources for each room.

Step Three. Navigate to the Edit Macro by Room and create the command that will make this work, basically setting the variable and triggering the events. This is the key to it all working. You want to set the variable for the source selected.

Step Four. Turning the Room Off. You will need to create a Device Event for Living Room Source Off. This is what will be triggered when the variable is set.

Here is the Living Room Source Off Device Event.

Next you will need to set the variable that will trigger this event. This variable should be set in the Room Off macro under Edit Special Macros. Note, for multiple rooms sharing sources, currently I have not found a way for true tracking to prevent sources from turning off in other rooms when that source is turned off in another room. I am sure this can be done with more variables and if/else or a more complex react procedure. For now I have removed the Off commands for the sources.

That is it. For multiple rooms and sources you will want to repeat these. It seems long and drawn out, but it really isn't. It goes quickly and will have many benefits for complex systems.

Checked that already.
I've noticed that my React settings do not have the "Becomes Logic Options", "Statement Becomes True" that are in your screenshots. Different version or is something up?

If you read the follow up post by Braden and myself you will see that the Logic Option in my first attempt is wrong. I changed that and I should not have. It needs to remain the default "Statement Remains or Becomes True".

Checked that already.
I've noticed that my React settings do not have the "Becomes Logic Options", "Statement Becomes True" that are in your screenshots. Different version or is something up?

Sounds like you are trying to use a TCL command for something. Read through my post on how to set it up. Look at where I am creating the various events. The only TCL command for React being used is in the Edit Room Macro.