Commit Graph

81 Commits

Author SHA1 Message Date
Stephan Hadinger 15e37ef0bb Change converted double to float in rules, and replaced trigonometric functions from stdlib with smaller versions. 2019-07-01 18:20:43 +02:00
Theo Arends 1b69502d9b Code optimization - Change for(uint8_t in for (uint32_t
Code optimization - Change for(uint8_t in for (uint32_t
2019-06-30 16:44:36 +02:00
Theo Arends 30adce5648 Revert "Code optimization - Change for(uint8_t in for (uint32_t"
This reverts commit 5e1eac3f74.
2019-06-30 15:56:55 +02:00
Theo Arends 5e1eac3f74 Code optimization - Change for(uint8_t in for (uint32_t
Code optimization - Change for(uint8_t in for (uint32_t
2019-06-30 15:47:32 +02:00
Theo Arends 8c132bd0ff Add rule System#Save executed just before a planned restart
Add rule System#Save executed just before a planned restart
2019-05-19 12:42:10 +02:00
Theo Arends dc3d0aea94 Add initial support for Scripts
Add initial support for Scripts as replacement for Rules. Default disabled but can be enabled in my_user_config.h (#5689)
2019-05-18 13:34:52 +02:00
Theo Arends 038079a865 Add rule support for single JSON value pair
Add rule support for single JSON value pair like {"SSerialReceived":"on"} by expanding it to {"SSerialReceived":{"Data":"on"}} allowing for trigger SSerialReceived#Data=on (#5638)
2019-05-15 16:31:13 +02:00
Theo Arends 0b6c62f5f9 Add support for Shelly 1PM Template
Add support for Shelly 1PM Template {"NAME":"Shelly 1PM","GPIO":[56,0,0,0,82,134,0,0,0,0,0,21,0],"FLAG":2,"BASE":18} (#5716)
2019-05-13 18:26:07 +02:00
Theo Arends 0dbbf413a8
Merge pull request #5604 from Staars/development
do not forget to handle the last vars_event and mems_event
2019-04-09 18:40:45 +02:00
Theo Arends be385ecb5c Add command WebColor
* Add rule Http#Initialized
 * Add command WebColor to change non-persistent GUI colors on the fly
   Use a rule like:
   rule3 on http#initialized do webcolor {"webcolor":["#eeeeee","#181818","#4f4f4f","#000000","#dddddd","#008000","#222222","#ff0000","#008000","#ffffff","#1fa3ec","#0e70a4","#d43535","#931f1f","#47c266","#5aaf6f","#ffffff","#999999","#000000"]} endon
   or
   rule3 on http#initialized do webcolor {"webcolor":["#eee","#181818","#4f4f4f","#000","#ddd","#008000","#222"]} endon
   to make color changes persistent)
2019-04-08 22:37:39 +02:00
Staars a5c4dcd5d2 do not forget the last vars_event and mems_event 2019-04-08 18:27:08 +02:00
Staars 1400a15076 always check for vars_events and mems_events 2019-03-29 09:42:50 +01:00
Theo Arends e1c92b701b Change NULL to nullptr
Change NULL to nullptr
2019-03-26 18:26:50 +01:00
Theo Arends 6922e657d9 Shrink code/flash space
Shrink code/flash space
2019-03-23 17:00:59 +01:00
Theo Arends baa5825569 Free some flash
Free some flash
2019-03-11 10:38:41 +01:00
Laurent Dong b87afc3bcb Code review: Copy string with strlcpy() instead of snprintf()
Copying string with snprintf() is unsafy and slow because it check and replace plcaehold (%?)
2019-03-08 13:24:02 -05:00
Theo Arends 06a9fbd792 Changed logging message handling
Changed logging message handling
2019-03-08 15:15:42 +01:00
Laurent dd27ade7ef Rules: Trigger Event with MQTT Subscriptions
Support subscribe/unsubscribe MQTT topics and trigger specified event with the subscribed MQTT topic.
You can subscribe a MQTT topic and assign an event name. Once we received subscribed MQTT message, an event will be automatically triggered. So you can set up a rule with "ON EVENT#<event_name> DO ..." to do whatever you want based on this MQTT message. The payload is passed as a parameter once the event been triggered. If the payload is in JSON format, you are able to get the value of specified key as parameter.
For example, if you have a Tasmota based thermostat and multiple temperature sensors in different place, usually you have to set up a centre home automation system like Domoticz to control the thermostat. Right now, with this new feature, you can write a rule to do this.
Two new commands in Rules:
1. Subscribe
Subscribe a MQTT topic (with or without key) and assign an event name to it.
Command format:
	Subscribe [<event_name>, <topic> [, <key>]]
		This command will subscribe a <topic> and give it an event name <event_name>.
		The optional parameter <key> is for parse the specified key/value from MQTT message
			payload with JSON format.
		In order to parse value from two level JSON data, you can use one dot (".") to split the key into two section.
		Subscribe command without any parameter will list all topics currently subscribed.
2. Unsubscribe
Unsubscribe specified MQTT event.
Command format:
	Unsubscribe [<event_name>]
		Unsubscribe a topic subscribed by specify the event name.
		If no event specified, Unsubscribe all topics subscribed.
Examples:
1.
	Subscribe BkLight, Tasmota/BackyardLight/stat/POWER
		And define a rule like:
	Rule1 on event#BkLight=ON do ruletimer4 60 endon
2.
	Subscribe DnTemp, Tasmota/RoomSensor1/stat/SENSOR, DS18B20.Temperature
		Define a rule to deal with the MQTT message like {"Time":"2017-02-16T10:13:52", "DS18B20":{"Temperature":20.6}}
	Rule1 ON EVENT#DnTemp>=21 DO ... ENDON
2019-02-23 22:33:09 -05:00
Theo Arends 280dd25a8b Optimize RAM for expression
Optimize RAM for expression and add two more constant variables (#5275)
2019-02-19 14:49:15 +01:00
Theo Arends 14d5f7fb54 Fix GUI password and Add rule expression
* Fix GUI wifi password acception starting with asteriks (*) (#5231, #5242)
 * Add rule expression enabled  by define USE_EXPRESSION in my_user_config.h (#5210)
2019-02-16 16:17:17 +01:00
Laurent 4b4b3709ad Introduce Expression in Rules
Support use an expression as paramter in some rule commands, include Var<x>, Mem<x> and Ruletimer<x>.
Expression is constructed by constants (float number), variables (var<x>, mem<x>, Time, Uptime, Sunrise, Sunset),  operators and round brackets.
Currently support 6 operators, order by priority from high to low:
^  (power)
% (modulo)
*, /
+, -
Commands examples:
Var1 3.14 * (MEM1 * (10 + VAR2 ^2) - 100) % 10 + uptime / (2 + MEM2)
Ruletimer4 Time - Sunrise + MEM2/2
2019-02-12 21:46:42 -05:00
Theo Arends ee2660b2bc Update xdrv_10_rules.ino
Move const to flash
2019-02-05 17:45:35 +01:00
Laurent Dong 09732c9f2d Add new compare operators ("==", "!=" ,">=" and "<=") for rule
Introduce new compare operators for rules and did some optimization as well.
The new "==" operator act as a real number comparison instead of the previous "=" operator which is doing string comparison which result in FALSE for "1 + 1 = 2". For example:
rule1 on event#test do backlog var1 1;add1 1; event CompareWith2=2 endon on event#CompareWith2=%var1% do ledpower on endon
ledpower off
rule1 on
event test
2019-02-05 09:34:17 -05:00
Theo Arends 304ac6fe44 6.4.1.12 code changes (byte/boolean)
6.4.1.12 20190128
 * Change code use of boolean to bool and byte to uint8_t
 * Change code uint8_t flags to bool flags
2019-01-28 14:08:33 +01:00
Theo Arends 0186a97cb0 Fix allowable MAX_RULE_VARS to 16
Fix allowable MAX_RULE_VARS to 16 (#4933)
2019-01-15 16:30:20 +01:00
Adrian Scillato 1d23c0b0c5
New Triggers for Rules: VARx#STATE and MEMx#STATE
Added new triggers for rules: `VARx#STATE` and `MEMx#STATE`

These new triggers allows to execute commands when VARs or MEMs change their values.

This is useful for automations where the parameter sent to Tasmota by MQTT is a SetPoint for example.

Before these triggers, the approach was using an `EVENT` to store a value but some components in home automation softwares can't use `cmnd/sonofftopic/EVENT SETVAR=25`, where `cmnd/sonofftopic/EVENT` is the mqtt message and `SETVAR=25` is the payload.

With this new triggers, it will be as simple as `cmnd/sonofftopic/VAR 25` so any automation software can use it.

_(Using `cmnd/sonofftopic/EVENT SETVAR=` as mqtt message and `25` as payload is not understood by Tasmota)_
2019-01-04 16:26:37 -03:00
Theo Arends 447ec6256e 6.4.1.4 Update Copyright (C) 2019
6.4.1.4 20190101
 * Update Copyright (C) 2019
2019-01-01 13:55:01 +01:00
Theo Arends 5a44b12870 6.4.1.2 Rewrite Switch driver
6.4.1.2 20181228
 * Change switch driver making it modular and introduce input filter (#4665, #4724)
 * Add define DS18B20_INTERNAL_PULLUP to select internal input pullup when only one DS18B20 sensor is connected eliminating external resistor (#4738)
 * Add variable %timestamp% to rules (#4749)
2018-12-28 16:35:19 +01:00
Adrian Scillato 4fcbaf99be
Add variable %timestamp% to be used in rules
This PR adds a new variable %timestamp% to be used in a rule to allow the user to include the Time Stamp as Tasmota has for Status, Sensors, etc, for example:

Command:

publish stat/topic/sensor {"Time":"%timestamp%","mysensor":"%var1%"}

Output:

{"Time":"2018-12-27T12:52:57","mysensor":"1"}

(https://github.com/arendst/Sonoff-Tasmota/issues/4734)
2018-12-27 14:57:27 -03:00
Theo Arends c1102a4863 6.4.0.2 Fix possible dtostrf bos
6.4.0.2 20181221
 * Fix possible dtostrf buffer overflows by increasing buffers
2018-12-21 16:17:06 +01:00
Adrian Scillato c68fe7e7ad
RULES: Added BREAK as an alternative ENDON 2018-12-01 19:00:34 -03:00
Adrian Scillato 7f2b3643f5
RULES: Added BREAK as an alternative ENDON
RULES: Added BREAK as an alternative ENDON that will stop the execution of the following rules.

If a rule that ends with BREAK, is triggered, then the following rules of that set will not be executed. This is useful for cases like: https://github.com/arendst/Sonoff-Tasmota/issues/4477
2018-12-01 18:12:33 -03:00
Adrian Scillato e3d1971e51
Add Command CalcRes 2018-11-26 23:08:23 -03:00
Adrian Scillato f7a8f39f89
Added command CalcRes 2018-11-26 21:22:44 -03:00
Erik bee50cba06 Add support for sensor discovery 2018-11-21 19:21:51 +01:00
andrethomas 4a7e7b0dbb Change C functions with () to (void) 2018-11-14 15:32:09 +02:00
Theo Arends 9fef82736d Prep drivers for management
Prep drivers for management
2018-11-07 10:30:03 +01:00
Adrian Scillato bcc9432214
Added Dimmer Trigger for Rules
For example

rule on Dimmer#state<30 do ... endon
rule on Dimmer#boot<10 do ... endon
2018-10-01 13:13:47 -03:00
Adrian Scillato a67efa0ab2
Added new triggers for rules on boot time
To make it possible to trigger a rule at boot time with the state of the switches or relays (in order to take decisions), 2 new trigger types has been added: 

* SWITCH1#BOOT

to be used like:

ON SWITCH1#BOOT DO ...  %value% ENDON
ON SWITCH1#BOOT=0 DO .... ENDON
ON SWITCH1#BOOT=1 DO .... ENDON

and

* POWER1#BOOT

to be used like:

ON POWER1#BOOT DO ...  %value% ENDON
ON POWER1#BOOT=0 DO .... ENDON
ON POWER1#BOOT=1 DO .... ENDON
2018-09-26 23:02:55 -03:00
Theo Arends 6939d6eead Fix Shelly Ghost and Rule sensors
* Change pinmode for no-pullup defined switches to pullup when configured as switchmode PUSHBUTTON (=3 and up) (#3896)
 * Add delay after restart before processing rule sensor data (#3811)
2018-09-26 11:56:58 +02:00
Theo Arends 01ce1b0c91 Fix Shelly2 monitoring
Disable serial logging on Shelly2 as serial is being used by energy monitoring (#3878)
2018-09-23 13:55:42 +02:00
Theo Arends f05fc71d67 Fix rule trigger POWER1#STATE
Fix rule trigger POWER1#STATE execution after restart and SetOption0 is 0 (#3856)
2018-09-22 17:37:49 +02:00
Theo Arends 7cd9224819 6.2.1.3 - Change drop down list
6.2.1.3 20180907
 * Change web Configure Module GPIO drop down list order for better readability
 * Fix showing Period Power in energy threshold messages
 * Fix ButtonRetain to not use default topic for clearing retain messages (#3737)
2018-09-08 17:18:31 +02:00
Theo Arends 55b43734d8 6.1.1.13 - Fixes
6.1.1.13 20180828
 * Fix 6.1.1.12 regression of Mem and Var default handling (#3618)
 * Optimizations
2018-08-28 11:10:32 +02:00
Theo Arends f8666c0410 Some requested additions
* Add optional MQTT_TELE_RETAIN to Energy Margins message (#3612, 3614)
 * Add Individual HSBColorX commands (#3430, #3615)
 * Add RuleX debug options 8,9,10 (StopOnError) to control RuleX execution status after an exception restart (#3607)
2018-08-28 10:26:33 +02:00
Theo Arends d4931f7b11 Fix handling default names Pt.2
Fix handling default names Pt.2
2018-08-27 14:53:09 +02:00
Theo Arends 9978381c94 Fix handling deafult names
Fix handling use of default names when using names starting with shortcut character (#3392, #3600)
2018-08-27 13:06:22 +02:00
Adrian Scillato f70e4ab783
Added time parameters as variable comparison
Added %sunrise%, %sunset%, %uptime% and %time% to be used in rules comparison like:

on Time#Initialized do backlog event checksunrise=%time%; event checksunset=%time% endon
on event#checksunset>%sunset% do power3 1 endon
on event#checksunrise<%sunrise% do power3 1 endon
2018-08-27 04:59:17 -03:00
Theo Arends bbd2529914 Sleep fixes part 2 and 3 of 3
* Change scheduler phase 2/3 - Fixed when sleep is enabled: Blinktime (#3581)
 * Change scheduler phase 3/3 - Some sensor update timings: AdcEvery 200 -> 250, Senseair 300 -> 250, SDM120 300 -> 250, SDM630 300 -> 250
2018-08-26 17:10:18 +02:00
Theo Arends f090050e69 6.1.1.11 - Sleep fixes part 1
6.1.1.11 20180826
 * Change scheduler phase 1 - Fixed when sleep is enabled: Uptime, Delay, PulseTime and TelePeriod (#3581)
2018-08-26 15:42:35 +02:00