From ago control wiki
(Difference between revisions)
Jump to: navigation, search
m (Example 4)
(How to)
Line 74: Line 74:
Some blocks have little blue stars on top left corner, clicking on this star open a popup to add some features to the block.
Some blocks have little blue stars on top left corner, clicking on this star open a popup to add some features to the block.
== More info ==
You can find more info on Blockly as a language (i.e. not agocontrol related) at [ Blockly language documentation]
== Variables ==
== Variables ==

Latest revision as of 21:37, 25 December 2016


[edit] Create events using blocks

[edit] Introduction

First of all you need to know how agocontrol is working:

  • When a device change its status, an event is triggered into agocontrol.
  • This event is propagated among all agocontrol modules and catched by event handler.
  • An event is containing some related informations. All this informations are called "event content"

With an example:

I have a temperature sensor and when this device detects a temperature changing, the event "temperature has changed" is triggered. Agocontrol system catch this event and execute all actions associated to this event. The event "temperature has changed" is containing the sensor unique id (uuid) and the new temperature value.

Now you know how agocontrol is working so you should be able to create an action.

[edit] Getting started

Agocontrol proposes an easy way to create these actions without any computer skills (or a little bit) using blocks construction. Dashboard is composed of:

  • an area on top with buttons
  • a menu on the left
  • a construction area

[edit] Top area

Top area is composed of buttons:

  • Save button: save your action. First saving request you an action name.
  • Load button: open a popup that list all existing actions. This popup allows you to delete useless actions.
  • Check button: click on it if you want to check if there are some mistakes on your action
  • Show button: open a popup to show you generated script from your blocks.
  • Clear button: reset construction area.

[edit] Menu

[edit] Root sections

The menu of the left is divided on sections:

  • "Logic" section contains logic block like if and comparison
  • "Loops" section allows you to iterate on something
  • "Math" section adds some mathematical operations
  • "Colour" adds color picker
  • "Text" section contains all you need to manipulate strings
    • If you use special chars in your text boxes to send messages, example "ø" then you must use the html-code &#248 to substitute. Look at this page to get codes [1]
  • "List" section allows you to manipulate array
  • "Datetime" gives you access to date and time functions
  • "Common" appends common functions (like print something on screen)
  • "Variables" allows you to declare local variables to save informations of your action
  • "Procedures" contains blocks to add functions in your action
  • "Agocontrol" is a specific section that contains agocontrol inventory, devices, values... This section is explained above

[edit] Agocontrol section

Agocontrol section contains specific blocks that will allow you to interact with the home automation system:

  • "Content" section
    • "triggered event" block catches current event content (remember, content contains the event triggered, its values...)
    • "content prop" block gives you access to current content properties (ie current temperature, uuid of device that triggers event...)
  • "Inventory" section
    • "device property value" block returns value of specified agocontrol device
  • "Device" section gives access to device uuids or names
    • "uuid" returns uuid of selected device
    • "device name of uuid" returns device name of specified uuid (useful with "content prop" block)
  • "Event" section gives acces to event names
  • "Actions" section
    • "Send command" allows you to control agocontrol sending commands like send mail or sms, open or close your shutters...
    • "Sleep" pauses your script during amount of specified command
  • "Variables" section gives access to agocontrol internal variables. Very useful to keep in mind some information.

[edit] Construction area

By default, on construction you should see default blocks:

  • a logic "if" block that creates a condition
  • a content "triggered event" block that catches an event
  • an "event" block that specifies the event you want to catch

[edit] How to

Building an action is really simple: drag and drop blocks from left menu to construction area and plug them together. Blocks inputs and outputs have type checking to drive you. Some blocks have little blue stars on top left corner, clicking on this star open a popup to add some features to the block.

[edit] More info

You can find more info on Blockly as a language (i.e. not agocontrol related) at Blockly language documentation

[edit] Variables

You have 2 ways to save data between different script executions:

  • using agocontrol system variables "System variables"
  • or using script variables "Local variables"

[edit] System variables

System variables are variables that own to agocontrol. You can declare them using dedicated config page (configuration->variables)

Some system program update those variables like agotimer that updates time associated variables (hour, minute...)

Those variables are stored by agocontrol and restored after agocontrol restart.

Under blockly, you can only update their values. You can't declare new ones using a script.

Just a reminder, but weekday value in event.environment.timechanged are Monday=1, Tuesday=2, Wednesday=3, Thursday=4, Friday=5, Saturday=6 and Sunday=7

[edit] Local variables

Local variables are variables that own to your script. By default a variable lives during your script execution and finally is lost.

If you need a variable along all your script execution, you can prefix a local variable with "ago_". Those kind of variable will be stored at end of your script execution and restored at next script execution allowing you to do some stuff according to previous state. This script context has no hard storage, it means if agocontrol is stopped, you will lose this context Make sure to check if variable exists before using it or you will get script execution failure! Moreover, when you save your script, this context is cleared.

[edit] Example

This example prints ago_persistentvar value each minutes

Blockly variable.jpg

[edit] Examples

Examples of what can be done with Blockly can be found below, if you have questions relating to the examples please post on the [2]

[edit] Example 1

Every Monday 01.37 send an email, with temperature + distance measurement to an email address

Blockly TempDistance2Email.png

[edit] Example 2

If today is an odd number day of the month, at 7pm turn on a switch for an hour then switches it off and turns another one on for another hour.

Blockly Irrigation.png

[edit] Example 3

If temperature is rising above trigger value, then only send 1 email or sms until the temperature is below the trigger value. SMS script is this example have been disabled, but is usable if you enable it. First check if the ago_ variable is defined, if not then define. Use "ago_" in your variable, then the variable value will be remembered outside from your blockly script. With credit to Tang The textbox is combined with the temperature device property value and this provides the actual temperature to be included in the message Send alert only once.PNG

[edit] Example 4

When sunset switch on the lamp, and switch it off when it's bedtime Sunset action until bedtime.png

[edit] More examples in the forum

Upload your Blockly scripts there to teach and inspire other users here: [3]

Personal tools