[BUG] some rule has got stuck in the memory

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
paveleremin
Normal user
Posts: 12
Joined: 29 Dec 2016, 10:19

[BUG] some rule has got stuck in the memory

#1 Post by paveleremin » 11 Jan 2017, 00:36

I'm try to prepare a code at my Sonoff switch while I'm waiting for Sonoff TH.
My plan is use Openhab to control values and use Sonoff TH as a thermostat.
At Sonoff switch I used Dummy device as a sensor(dht#temp).

Here is the Rules code that I'm working on:

Code: Select all

on highThreshold do
  if [dht#temp]>[thermostat#temp]
    gpio,12,0
  endif
endon

on lowThreshold do
  if [dht#temp]<[thermostat#temp]
    gpio,12,1
  else
    event,highThreshold
  endif
endon

on checkThresholds do
  if [thermostat#enabled]=1
    event,lowThreshold
  else
    gpio,12,0
  endif
endof

on dht.temp do
  TaskValueSet 12,1,%eventvalue%
  Publish /%sysname%/dht/temp,%eventvalue%
endon

// seems issue start from here, this not work
on dht#temp do
  event,checkThresholds
endon

on thermostat.enabled do
  Publish /%sysname%/thermostat/enabled,%eventvalue%
  TaskValueSet 4,1,%eventvalue%
  event,checkThresholds
endon

on thermostat#enabled do
  Publish /%sysname%/thermostat/temp,[thermostat#temp]
  Publish /%sysname%/thermostat/hysteresis,[thermostat#hysteresis]
endon

on thermostat.temp do
  TaskValueSet 4,2,%eventvalue%
  Publish /%sysname%/thermostat/temp,%eventvalue%
  event,checkThresholds
endon

on thermostat.hysteresis do
  TaskValueSet 4,3,%eventvalue%
  Publish /%sysname%/thermostat/hysteresis,%eventvalue%
  event,checkThresholds
endon

on relay#switch do
  if [relay#switch]=1
    gpio,13,0
  else
    gpio,13,1
  endif
endon

on button#switch=0 do
  if [relay#switch]=0
    gpio,12,1
  else
    gpio,12,0
  endif
endon
I used R148. I increased RULES_MAX_NESTING_LEVEL to 5.
The issue is: after a lot of variants of Rules I got some issue in MQTT from my devise:

Code: Select all

Client mosqsub/13940-peremin-l received PUBLISH (d0, q0, r0, m0, '/sonoffF009/thermostat/hysteresis', ... (1 bytes))
1
Client mosqsub/13940-peremin-l received PUBLISH (d0, q0, r0, m0, '/sonoffF009/dht/temp', ... (12 bytes))
%eventvalue%
Look at the /sonoffF009/dht/temp right now fire after/sonoffF009/thermostat/hysteresis why? :-O
I think something has got stuck in the memory after my experements with the Rules

User avatar
paveleremin
Normal user
Posts: 12
Joined: 29 Dec 2016, 10:19

Re: [BUG] some rule has got stuck in the memory

#2 Post by paveleremin » 11 Jan 2017, 18:21

It was my fault, I have a typo "endof" instead of "endon"
Here is the final code for thermostat:

Code: Select all

on highThreshold do
  if [dht#temp]>[thermostat#temp]
    gpio,12,0
  endif
endon

on lowThreshold do
  if [dht#temp]<[thermostat#temp]
    gpio,12,1
  else
    event,highThreshold
  endif
endon

on checkThresholds do
  if [thermostat#enabled]=1
    event,lowThreshold
  else
    gpio,12,0
  endif
endon

on dht.temp do
  TaskValueSet 4,1,%eventvalue%
  Publish /%sysname%/dht/temp,%eventvalue%
endon

on dht#temp do
  event,checkThresholds
endon

on thermostat.enabled do
  Publish /%sysname%/thermostat/enabled,%eventvalue%
  TaskValueSet 3,1,%eventvalue%
  event,checkThresholds
endon

on thermostat#enabled do
  Publish /%sysname%/thermostat/temp,[thermostat#temp]
  Publish /%sysname%/thermostat/hysteresis,[thermostat#hysteresis]
endon

on thermostat.temp do
  TaskValueSet 3,2,%eventvalue%
  Publish /%sysname%/thermostat/temp,%eventvalue%
  event,checkThresholds
endon

on thermostat.hysteresis do
  TaskValueSet 3,3,%eventvalue%
  Publish /%sysname%/thermostat/hysteresis,%eventvalue%
  event,checkThresholds
endon

on relay#state do
  if [relay#state]=1
    gpio,13,0
  else
    gpio,13,1
  endif
endon

on button#state do
  if [relay#state]=0
    gpio,12,1
  else
    gpio,12,0
  endif
endon
Hysteresis here is hardcoded, if you will use for thermostat#temp and dht#temp with decimal=1 it will be 1 degree. If you will use decimal=0 hysteresis will be 2 degree.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 10 guests