Aeotec Smart Switch 6 change in Power level not triggering Rule

  • Platform information:
    • OS: _Ubuntu 18.04
    • openHAB version: 2.3

Hi I would like some help, I don’t seem to be able to get a change in power reading to trigger a rule.

My ultimate goal is to have an email sent when power level changes below a certain level, then if it does not return above that level after 30 mins send the email again.

I have tested the sendEmail command at it is all set up correctly, I have even tried to make a simple rule to turn my TV on when the power level drops (without the timer) but this does not work either.

my .rules file is:

// Imports
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

// Global Variables
var boolean Override = false
var Timer _timer_001_A = null

rule "Send_PC_email"
when
	Item PC_ElectricMeterWatt changed
then
  if (((PC_ElectricMeterWatt < 230) && (Override == false))) {
	sendMail("someone@gmail.com", "PC Error!", "")

    Override = true
  }

  else {
  if (((PC_ElectricMeterWatt < 230) && (Override == true))) {
    if (_timer_001_A = null) {
      _timer_001_A = createTimer(now.plusMinutes(30)) [|
        _timer_001_A.cancel()
        _timer_001_A = null
        Override = false
      ]
    }
  }
  else if(_timer_001_A != null) {
    _timer_001_A.cancel()
    _timer_001_A = null
  }
  }
end

All i see in the console Log is this, the rule does not seem to trigger:

11:33:50.698 [INFO ] [smarthome.event.ItemStateChangedEvent] - PC_ElectricMeterWatts changed from 313.466 to 212.715
11:34:00.004 [DEBUG] [rsistence.rrd4j.internal.RRD4jService] - Stored 'PC_ElectricMeterWatts' with state '212.715' in rrd4j database

Thanks

It’s all good I fixed it myself it was a typo and I had to put .state at the end of the item, but I will leave the post here just in case someone is looking to do something similar.

New .rules file:

// Imports
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

// Global Variables
var boolean Override = false
var Timer _timer_001_A = null

rule "Send_PC_email"
when
	Item PC_ElectricMeterWatts changed
then
	logInfo("Send_Mining_PC-email","Rule Trigered")
  if (((PC_ElectricMeterWatts.state < 230) && (Override == false))) {
	sendMail("someone@gmail.com", "PC Error!", "")
	logInfo("Send_PC-email","Email Sent")
    	Override = true
  	}

  else if ((PC_ElectricMeterWatts.state < 230) && (Override == true)){
	if (_timer_001_A == null) {
	
		logInfo ("Send_PC-email","set timer to {}",now.plusMinutes(30).toString)
      		_timer_001_A = createTimer(now.plusMinutes(30)) [|
      		Override = true
		logInfo ("Send_PC-email","Overriding")
      		]
    		}
	}
    	else if(_timer_001_A != null) {
    		_timer_001_A.cancel()
    		_timer_001_A = null
    		Override = false
		
  	}
  
end

Thanks, can you change your posts using the code fences, please

You don’t need the import-lines.

if (((PC_ElectricMeterWatts.state as Number) < 230) && (Override == false)) {
...
if (_timer_001_A === null) {

Thanks

Was not sure how to do that.

And that one too…

else if(_timer_001_A !== null) {