Showing posts with label sensor. Show all posts
Showing posts with label sensor. Show all posts

Tuesday, November 8, 2016

Triggers

After some playing with gateway functions and Home Automation Systems, I have realized that I often need to pass some data from one sensor to another. Either periodically every time there is new value or just when there is a condition met. These conditions are mostly rather simple, like voltage on battery powered node is reaching low level, or turn on light then there is a person in front of PIR alarm sensor. Having a gateway, I can collect the data. Pass it through Ethernet to MQTT, then to some automation server like NodeRed, process the state and send the result all the way back to another remote sensor or relay. I thought this can be a bit overkill and always require a running computer or at least a Raspberry Pi, so the triggers were born.

Triggers is new option in firmware 1.7.3, it offers as the name suggest, triggering events on sensors or zones. The overview is shown on following picture:



There can be up to 10 triggers created, or more if you set it in code, that can do various task or react on zone state or sensor value.

The setting of each trigger is shown on right. You can assign name up to 15 characters for each trigger and turn it On or Off. Important is the source address, that is the sensor or zone number, that triggers the subsequent action. Symbol is condition describing when the trigger should happen. Put it simple, it is "if ... then" in code. There can be "=","!","<",">","A", that is equal, not equal, less then, more then or always. Value is a float number that the condition is compared to, except for symbol always that is processed anyway. Then there is logging flag, it means the trigger event is passed to logger, which can then send SMS or email, based on logger setting. Pass flag will indicate that when the event is triggered, gateway will pass the value to To address sensor. Pass once flag is preventing subsequent sending of value for same trigger, and it is reset when condition is negative. Pass Off will send first message to recipient after the condition is negative. Pass value or constant switch is deciding if a source address value is passed to destination address or the constant present in Constant On and Constant Off.

With above you can dynamically assign many events that can help you improve your home automation directly in friendly web interface. On first example picture above, there are 2 triggers created. First to send SMS or email when battery is reaching low level on my meteo station. And second will turn on light whenever there is PIR sensor triggered on zone called stairs. Simple as that, and it just works!

You can create many other scenarios for triggers, such as simply passing data from one sensor to another. I have in mind passing external temperature and humidity to internal temperature and humidity sensor that turns On/Off fan in bathroom. This way you can compare the two values and make better decision.






Monday, December 28, 2015

Remote node code

Just created new GitHub repositories for remote node code and put links to them on the page here on blog.

In the code there is visible declaration of sensors and authentication units, and their way of registration to gateway. In the iButton node, there is also sound and led code that is based on tone library and performs feedback to user. Wired nodes use my own RS485 library, otherwise standard Arduino libraries are used.

Saturday, February 7, 2015

Web interface - sensors

Sensor configuration page has a lot similar with authentication units. Sensor can be connected by wire(RS485) or wireless(RFM12B). It is shown in the address field. "W" stands for wired and "R" for Radio. Units in range 1-14 are wired and 17-143 are connected wireless. Currently the firmware recognize following types:
  • Temperature
  • Humidity
  • Pressure
The type and address is coded in the registration message in the sensor firmware. Other values can be configured and are stored in unit in chip EEPROM. As you can see above you can turn the sensor On or Off. Also you can allow the sensor value to be propagated to MQTT. The default path is "OHS/Group_name/Sensor/Sensor_Type/Sensor_local_address". Example looks like this:

OHS/Zahrada/Sensor/Temperature/0  23.00
OHS/Zahrada/Sensor/Humidity/0  53.00
OHS/Zahrada/Sensor/Temperature/1  24.04
OHS/Zahrada/Sensor/Pressure/0 998.38
OHS/Dilna/Sensor/Temperature/0   9.48
OHS/Domek/Sensor/Temperature/0  13.02
OHS/Garaz/Sensor/Temperature/0  12.06

Last setting is the group name the sensor belongs to.

Sensors are dynamically added when they first join the network. The Sensor type can be chosen to any possible, as long as its value can be stored i a float variable. Main unit does not care about the sensors at all, it doesn't do any computation with it values, and also it does not verify the content. Main purpose is to act as a gateway for MQTT to NodeRed or similar tool. Only value that indicate the health of the sensor is time-stamp called last OK, that indicates delivery time of last message from sensor.

Sensors are defined in the code by following struct:


  uint8_t address;
  char    type;
  uint8_t number;
//          |- MQTT publish
//          ||- Free    
//          |||- Free
//          |||||||- Group number
//          |||||||- 0 .. 15
//          |||||||- 
//          |||||||- 
//          ||||||||-  Enabled   
//          00000000
  uint8_t setting;
  float   value;
  systime_t last_OK = 0;

In the future, the parameters for sensors, and also for authentication units, will extend as they will be battery monitored. I would like main board to take care of the sensors battery life in form of some flag and also sms.