Sonoff Tasmota creating a rule

Hi All,

I am totally new to all of this and have been trying to create a small rule which I can build on,
So the devices I am using are sonoff th16 and a sonoff pow r2,
the rule is as follows,
rule “Outside Temp below 10”
when
Item so5_temp Changed
then
if(so5_temp.state as Number < 11) {
SoPow1_SW_ON_OFF.sendCommand(ON)
}
end

and then in the log file the warning is 

Configuration model ‘Outside Temp Below 11.4.rules’ has errors, therefore ignoring it: [3,3]: no viable alternative at input ‘Changed’
[5,31]: no viable alternative at input ‘11’

Obviously the word “changed” is some how incorrect and the number 11 is also,

anyone able to shed light on what may be needed here, please ignore the title of the file as I have realized decimal places do not work.

cheers

help with the above rule and why the errors occur

here is the rule I am having trouble with

rule “Outside Temp below 11”
when
Item so5_temp Changed
then
if(so5_temp.state as Number < 11) {
SoPow1_SW_ON_OFF.sendCommand(ON)
}
end

and the error

WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘Outside Temp Below 11.4.rules’ has errors, therefore ignoring it: [3,3]: no viable alternative at input ‘Changed’
[5,31]: no viable alternative at input ‘11’

If the items are correct i think you have an syntax error in your rule.

Just try:

rule “Outside Temp below 11”
when
Item so5_temp changed
then
if(so5_temp.state as Number < 11) {
SoPow1_SW_ON_OFF.sendCommand(ON)
}
end

The Changed should be lowercase i think.

Ok, this has changed the error a little

Configuration model ‘Outside Temp Below 11.4.rules’ has errors, therefore ignoring it: [1,6]: no viable alternative at input ‘“’

all but one item, not sure how this could be an error ?

So I have replaced the quotations and the rule looks like this

rule “Outside Temp below 11”
when
Item so5_temp changed
then
if(so5_temp.state as Number< 11) {
SoPow1_SW_ON_OFF.sendCommand(ON)
}
end

and now the error looks like

[WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘Outside Temp Below 11.4.rules’ has errors, therefore ignoring it: [5,30]: no viable alternative at input ‘11’

Not sure what is going wrong here
anyone help with this ?

You have also a syntax error in your number conversion:

if(so5_temp.state as Number< 11) {

should be:

if ((so5_temp.state as Number) < 11) {

Hey thanks so much,

so far there are no errors in the log and just waiting for it to trigger,

cheers

Even though I have no errors the rule only turns the sopow1 on, this is a sonoff POW R2, the device so5_temp is a sonoff th16.

rule “Outside Temp below 14 over 20”
when
Item so5_temp changed
then
if((so5_temp.state as Number) > 20) {
SoPow1_SW_ON_OFF.sendCommand(ON)
}
else if((so5_temp.state as Number) < 14) {
SoPow1_SW_ON_OFF.sendcommand=(OFF)
}

end

any ideas ?

Just changed the else if send command as i was messing around with +

rule “Outside Temp below 14 over 20”
when
Item so5_temp changed
then
if((so5_temp.state as Number) > 20) {
SoPow1_SW_ON_OFF.sendCommand(ON)
}
else if((so5_temp.state as Number) < 14) {
SoPow1_SW_ON_OFF.sendcommand(OFF)
}

end

Which did not work either.

messing with =

In that rule you are NOT sending any command to so5_temp! However, isn’t this an item that only shows a temperature?

I was trying to send a command to sopow1_SW_ON_OFF, this seems to be happening but only an on command

That is correct, so what is your problem?
Note that the command in the elseif case has a typo (.sendCommand).

so i have made the rule simple, and it still does not turn sopow1_SW_ON_OFF off,

Please can someone help?

where am I going wrong
rule “Outside Temp below 12”
when
Item so5_temp changed
then
if((so5_temp.state as Number) < 12) {
SoPow1_SW_ON_OFF.sendCommand(OFF)

}

end

Just tested this one on my system:

rule "“Temperature switching"
when
  Time cron "10 * * * * ?"
then
  if((Light_TH_Temperature.state as Number) < 10) {
    logInfo("Testrule", "Low Temperature={}",Light_TH_Temperature.state )
    Light_TH.sendCommand(OFF)
  } else
  {
    logInfo("Testrule", "High Temperature= {}",Light_TH_Temperature.state)
   Light_TH.sendCommand(ON)
  }
end

and it is working!
my log shows:
2019-04-07 11:03:10.037 [INFO ] [ipse.smarthome.model.script.Testrule] - Low Temperature= 17.3

Where is your problem? Check if all item names are spelled correctly (so5_temp versus SoPow1_SW_ON_OFF) The use of lower and upper case does matter!
Use some logInfo lines as in my example in order to see what is going on.

This all assumes that you can switch the device using the item SoPow1_SW_ON_OFF.

Update,

The first half of the rule acts instantly, the else if acts when the device does a MQTT update, how can I adjust this ?

rule “sonoff-basic-01-switch POWER2”
when
Item Sonoff_TH16_3 changed
then
if(Sonoff_TH16_3.state == ON) {
SoPow1_SW_ON_OFF.sendCommand(ON)
Son_4CH_Pro_CH1.sendCommand(ON)

}else if(Sonoff_TH16_3.state == OFF && SoPow1_SW_ON_OFF == ON) {
	SoPow1_SW_ON_OFF.sendCommand(OFF)
	Son_4CH_Pro_CH1.sendCommand(OFF)

}

end

Actually I have just found out the else if does not work at all? given I have copied examples of the forum and am very new to this I am not sure where I may have gone wrong?

Any Ideas ?

“elseif” instead of “else if”

so i have the switching rule working, now i am trying to get a temperature change rule working and am struggling with this, It all seems to be in order but have no results …

any suggestions

rule “Heat Transfer Fan on/off”
when
Item Sonoff_TH16_3_temperature changed
then
if(Sonoff_TH16_3_temperature.state > 20){
SoPow1_SW_ON_OFF.sendCommand(ON)
}

end

what is incorrect in this rule
I am using a sonoff th16 with tasmota firmware.