|  Help center

MiOS search

Use Variables in Meshbot Triggers and Actions

The example on this page shows how to create and dynamically update a variable in order to trigger specific actions.

Scenario:

  • You have a motion sensor in your bedroom that opens your bedroom curtains when it detects motion after your ‘Home’ house mode becomes active at 6 AM.
  • You want the curtains to open ‘one-time only’ when motion is detected in the morning, then remain open for the rest of the day. You do not want them to react to movement beyond this first opening.
  • The curtains will be closed in the evening by a different meshbot which shuts the curtains at sunset for the rest of the night.

Solution:

  • Create a Boolean variable called ‘Curtains Opened Today’, which has binary states of either ‘True’ or ‘False’.
  • Use this variable in meshbots to specifically control when the curtains should open.
Step-by-step Guide

Create a ‘Curtains Opened Today’ variable

  • Login to EZLogic then click ‘Advanced Scripting’ > ‘Variables’ > ‘Add New Variable’.
  • Choose ‘Boolean’ as the variable type and name it ‘Curtains Opened Today’. Give it an initial value of ‘False’ then click ‘Save’:

Meshbot 1 – Open the curtains

Create a meshbot to open the curtains IF the motion sensor detects movement AND ‘Home’ mode is active (6 AM) AND the curtains have not yet been opened today.

The meshbot actions will open the curtains and set the ‘curtains opened’ variable to ‘True’ if the conditions are met.

  • Click ‘Automation’ > ‘Meshbots’ > ‘Create New Meshbot’ > ‘Local’:

Name the meshbot ‘Curtains Opened today’ then add three triggers linked together by ‘AND’. The ‘and’ operator means all three triggers must become true before it will run your actions:

  • Trigger 1 – goes true if the ‘House Mode’ is ‘Home’. For this example, we assume ‘Home Mode’ becomes active at 6 AM in the morning.
  • Trigger 2 – goes true if the motion sensor device in your bedroom detects movement.
  • Trigger 3 – goes true if the ‘Curtains Opened Today’ variable has a status of ‘False’.

Tip – Place the motion sensor under a wardrobe or under your bed. This lets the sensor react to your feet walking around the room / getting out of bed, but won’t trigger if you just roll around in your sleep.

Your completed trigger group should look something like this:

Next, add the following two actions to meshbot 1:

  • Action 1 – Instructs your curtain device to open your bedroom curtains.
  • Action 2 – Switches the local variable ‘Curtains Opened Today’ from ‘True’ to ‘False’.

The complete action set in meshbot 1 should look something like this:

Click ‘Save’.

  • The meshbot will open the curtains when it detects movement after 6 AM and set the ‘Curtains Opened Today’ variable to ‘True’.
  • By setting the variable to ‘True’, you cause trigger 3 in the group you created earlier to go ‘false’. This, in turn, makes the entire trigger group go ‘false’.
  • Because the entire trigger group is ‘false’, no further ‘open’ commands are sent to the curtains for the rest of the day – even if motion is detected.

Next, you need to set up two more meshbots. One to close the curtains as evening approaches, and the other to reset the ‘Curtains Opened Today’ variable to ‘False’, ready for the next day.

Meshbot 2 – Close the curtains

  • Create a new meshbot as explained earlier.
  • Name the meshbot ‘Close Bedroom Curtains’.

Trigger

  • Select ‘Date and Time’ as the node type then ‘Special Time of Day’ > ‘Sunset’ *.
  • Choose ‘From Sunset to Midnight’ in the final box.**

* ‘Sunset’ is just one of the options you could choose for trigger 2. You could equally choose a specific time (like after 6.30 PM) or activate the trigger when ‘Night Mode’ becomes active.

** Don’t worry about this setting too much – your meshbot action won’t somehow get undone at midnight when the trigger goes false. You are effectively sending a one-time command to close the curtains when the trigger becomes true. However, you will not set a corresponding ‘False’ action to re-open the curtains when the trigger turns false.

Action

  • Select ‘Device’ as the controllable then your curtain device.
  • Select whatever command your device uses to close the curtains.

Your final meshbot # 2 should look something like this:

Click ‘Save’.

  • You now have two meshbots running. Meshbot 1 to open the curtains when you first get out of bed, and keep them open for the rest of the day. Meshbot 2 to close the curtains at sunset.
  • The only remaining step is to change the ‘Curtains Opened Today’ variable from ‘True’ to ‘False’ in order for meshbot 1 to work the next day.

Meshbot 3 – Reset the curtain variable

This final meshbot will revert the ‘Curtains Opened Today’ variable back to ‘False’ at 5.00 AM in the morning. Resetting the variable to ‘False’ satisfies trigger 2 in meshbot 1 and ensures the rest of meshbot 1 runs correctly.

You are free to choose a time other than 5 AM, but try to make it some time before ‘Day Mode’ begins (6 AM in our example).

  • Create a new meshbot as explained earlier.
  • Name the meshbot ‘Reset Curtain Variable’.

Trigger

  • Select ‘Date and Time’ as the node type then ‘Custom Time
  • Choose ‘After’ > ‘5 AM’ > ‘Everyday’ in the option menus.*

* See ‘Should I use ‘After’ or ‘At a time of day’?’ if you want to know why we choose ‘After’.

Action

  • Select ‘Local Variable’ as the controllable type.
  • Choose ‘Curtains Opened Today’ > ‘Set Variable’ > ‘False’.

Your final meshbot # 3 should look something like this:

Click ‘Save’.

That’s it. Meshbot 1 will open your curtains in the morning when you get out of bed and set the ‘Curtains Opened Today’ variable to ‘True’. This new setting stops meshbot 1 from continually sending ‘Open’ instructions to the curtains whenever the sensor detects motion. Meshbot 2 closes the curtains at sunset, and meshbot 3 resets the variable to ‘False’ at 5 AM so that meshbot 1 can run again the next day.