[SOLVED] Rule error: The argument 'state' must not be null [SOLVED]

I need help with this rule.

val number ACCESO	        = 0
val number SPENTO	        = 1

rule "feedback condizionatore notte status"

when

   Item condi_notte_on_off changed  

then 

 if (condi_notte_on_off == ON){
	condi_notte_state.postUpdate(ACCESO)
    }
	
else  {
	 condi_notte_state.postUpdate(SPENTO)
	 
    }
 	
end

When the active I receive the following error message:

Variable 'ACCESO' on rule file 'condizionatore notte status.rules' cannot be initialized with value 'org.eclipse.xtext.xbase.impl.XNumberLiteralImpl@42cf2c0a (value: 0)': An error occurred during the script execution: null 

Variable 'SPENTO' on rule file 'condizionatore notte status.rules' cannot be initialized with value 'org.eclipse.xtext.xbase.impl.XNumberLiteralImpl@1c3f08e3 (value: 1)': An error occurred during the script execution: null 

Rule 'feedback condizionatore notte status': The argument 'state' must not be null.

I tried to change the item from Switch to String, but with the same result.
Thanks in advance
Davide

if (condi_notte_on_off.state == ON) {

same answer in the log

val Number ACCESO = 0
val Number SPENTO = 1

uuuuh I always make these careless mistakes, thanks.
In the meantime I have expanded the rule. Everything works fine, but I don’t postUpdate the “condi_notte_state” item when the “condi_notte_on_off” item receives the command. (“night status conditioner feedback” rule)

val Number MAX_AUTO  		= 1
val Number MIN_AUTO         = 2
val Number MAX_PALA_SU      = 3
val Number MIN_PALA_SU      = 4
val Number DEUM_MAX_AUTO    = 5
val Number DEUM_MAX_SU      = 6
val Number DEUM_MIN_SU      = 7
val Number DEUM_MIN_GIU     = 8
val Number SPENTO	        = 9
val Number ACCESO	        = 10



rule "condizionatore notte"

when

  Item condi_notte_state changed
  
then

  if (condi_notte_state.state == MAX_AUTO ) {
  sendCommand ( condizionatore_notte_max_auto, ON)   
  }  
  if (condi_notte_state.state == MIN_AUTO ) {
  sendCommand ( condizionatore_minimo_auto, ON)   
  }
  if (condi_notte_state.state == MAX_PALA_SU ) {
  sendCommand ( condizionatore_max_su, ON)
  }
  if (condi_notte_state.state == MIN_PALA_SU ) {
  sendCommand ( condizionatore_min_su, ON)
  }
  if (condi_notte_state.state == DEUM_MAX_AUTO ) {
  sendCommand ( deumidificatore_notte_max_auto, ON)
  }
  if (condi_notte_state.state == DEUM_MAX_SU ) {
  sendCommand ( deumidificatore_notte_max_su, ON)
  }
  if (condi_notte_state.state == DEUM_MIN_SU ) {
  sendCommand ( deumidificatore_notte_min_su, ON)
  }
  if (condi_notte_state.state == DEUM_MIN_GIU ) {
  sendCommand ( deumidificatore_notte_min_giu, ON)
  }
  if (condi_notte_state.state == SPENTO ) {
  sendCommand ( condizionatore_notte_off, ON)  
  }
   
end


rule "feedback condizionatore notte status"

when

   Item condi_notte_on_off received command
  

then 

 if (condi_notte_on_off == ON){
	condi_notte_on_off.postUpdate(ON)
	condi_notte_state.postUpdate(ACCESO)
	
    }
	
 else  {
     //sendTelegram("bot1", "Clima zona notte SPENTO")
	 condi_notte_on_off.postUpdate(OFF)
	 condi_notte_state.postUpdate(SPENTO)
    }
 	
end

the Item “condi_notte_on_off” it’s a String Item and “condi_notte_state” it’s a Number Item

If you want to compare strings
if (myItem.state == “somestring”)
Or
var thatstring = “rhubarb”
if (myItem.state == thatstring)

If you want to update strings
myItem.postUpdate(“banana”)
Or
var otherstring = “custard”
myItem.postUpdate(otherstring)

As it says in the docs, it’s a good idea to use postUpdate method
myItem.postUpdate(newvalue)
Because the Item knows what type it is, it stands a much better chance of knowing what conversions to apply to strings and numbers.

i read the guide, and your help, thanks
i made this change:

rule "feedback condizionatore notte status"

when
   Item condi_notte_on_off received command  
then 

 if (condi_notte_on_off == "ON"){
	condi_notte_on_off.postUpdate("ON")
	condi_notte_state.postUpdate("ACCESO")
	
    }
	
 else if (condi_notte_on_off == "ON") {
     //sendTelegram("bot1", "Clima zona notte SPENTO")
	 condi_notte_on_off.postUpdate("OFF")
	 condi_notte_state.postUpdate("SPENTO")
    }
 	
end

but it not update item “condi_notte_state”, after the item “condi_notte_on_off” has gone ON or OFF and subsequently after i tried too this:

rule "feedback condizionatore notte status"

when
   Item condi_notte_on_off received command  
then 

 if (condi_notte_on_off == "ON"){
	condi_notte_on_off.postUpdate("ON")
	condi_notte_state.postUpdate("ACCESO")
	
    }
	
 if (condi_notte_on_off == "ON") {
     //sendTelegram("bot1", "Clima zona notte SPENTO")
	 condi_notte_on_off.postUpdate("OFF")
	 condi_notte_state.postUpdate("SPENTO")
    }
 	
end

same result

But condi_notte_on_off is a Switch type, not a String type. You have to handle different types in a different way.

More, if you want to look at the state of an Item, then you must say so by using the myItem.state method.
Answer was in post 2 already

In my items file “condi_notte_on_off” is a string type and the Item “condi_notte_state” is a number type.

Alright. What are you going to do about using .state ?

This won’t work then, sending a string to Number typcondi_notte_state.postUpdate("SPENTO")

I want to change the state of the number item “condi_notte_state” when the string item “condi_notte_on_off” received a command ON or OFF

when
   Item condi_notte_on_off received command
then
   if (receivedCommand == "ON") {   // compare string
       condi_notte_state.postUpdate( 2 )   // post number

I use receivedCommand here because when the rule triggers from a command, OH probably hasn’t processed that command to change the Item’s state yet.

change only “condi_notte_on_off”

rule "feedback condizionatore notte status"

when
   Item condi_notte_on_off received command 
then 

 if (receivedCommand == "ON"){
	//condi_notte_on_off.postUpdate("ON")
	condi_notte_state.postUpdate("10")
	
    }
	
 if (receivedCommand == "OFF"){
     //sendTelegram("bot1", "Clima zona notte SPENTO")
	 //condi_notte_on_off.postUpdate("OFF")
	 condi_notte_state.postUpdate("9")
    }
 	
end

Davide, in post 8 you said:

yet in latest version of rule

you are setting the state with a string (enclosed in" ")

ok, i corrected the error, but the item “condi_notte_state” continues to not update when “condi_notte_on_off” received command

Would you show us the events.log of this?

Is your string type Item placed on your sitemap using a Switch type widget, perhaps?

I was looking at the log file, sending nothing.
Portion of the log file after condi_notte_on_off receives the ON command:

2019-06-15 17:41:03.970 [vent.ItemStateChangedEvent] - condi_notte_on_off changed from OFF to ON
2019-06-15 17:41:04.370 [vent.ItemStateChangedEvent] - Reactive_power changed from -192.60 to -193.20
2019-06-15 17:41:07.850 [vent.ItemStateChangedEvent] - Frequency changed from 49.95 to 50.00
2019-06-15 17:41:09.014 [vent.ItemStateChangedEvent] - Total_active_energy changed from 2480.35 to 2480.36

item file:

Number condi_notte_state				                    ""		              (Condizionatori)                                                                                                                        
String condi_notte_on_off		         "condi notte  on/off"    <switch>         (Condizionatori)			              					     {mqtt="<[mosquitto:openhab/nodo10/condi_notte_on_off/command:state:default]"}

sitemap file:

Switch item=condi_notte_state    label="clima"           mappings=[ "1"="MAX", "2"="MIN", "3"="MX_S", "4"="MN_S", "9"="OFF" ]  
Switch item=condi_notte_state    label="deumi"           mappings=[ "5"="MAX", "6"="MX_S", "7"="MN_S", "8"="MN_G", "10"="ON"]	 
Switch item=condi_notte_on_off   label="stato"           mappings=[ON="ON", OFF="OFF"]

the rule:

val Number MAX_AUTO  		= 1
val Number MIN_AUTO         = 2
val Number MAX_PALA_SU      = 3
val Number MIN_PALA_SU      = 4
val Number DEUM_MAX_AUTO    = 5
val Number DEUM_MAX_SU      = 6
val Number DEUM_MIN_SU      = 7
val Number DEUM_MIN_GIU     = 8
val Number SPENTO	        = 9
val Number ACCESO	        = 10



rule "condizionatore notte"

when

  Item condi_notte_state changed
  
then

  if (condi_notte_state.state == MAX_AUTO ) {
  sendCommand ( condizionatore_notte_max_auto, ON)   
  }  
  if (condi_notte_state.state == MIN_AUTO ) {
  sendCommand ( condizionatore_minimo_auto, ON)   
  }
  if (condi_notte_state.state == MAX_PALA_SU ) {
  sendCommand ( condizionatore_max_su, ON)
  }
  if (condi_notte_state.state == MIN_PALA_SU ) {
  sendCommand ( condizionatore_min_su, ON)
  }
  if (condi_notte_state.state == DEUM_MAX_AUTO ) {
  sendCommand ( deumidificatore_notte_max_auto, ON)
  }
  if (condi_notte_state.state == DEUM_MAX_SU ) {
  sendCommand ( deumidificatore_notte_max_su, ON)
  }
  if (condi_notte_state.state == DEUM_MIN_SU ) {
  sendCommand ( deumidificatore_notte_min_su, ON)
  }
  if (condi_notte_state.state == DEUM_MIN_GIU ) {
  sendCommand ( deumidificatore_notte_min_giu, ON)
  }
  if (condi_notte_state.state == SPENTO ) {
  sendCommand ( condizionatore_notte_off, ON)  
  }
   
end


rule "feedback condizionatore notte status"

when
   Item condi_notte_on_off received command
then 

 if (receivedCommand == "ON"){
      //sendTelegram("bot1", "Clima zona notte ACCESO")
	//condi_notte_on_off.postUpdate("ON")
	condi_notte_state.postUpdate( ACCESO )
	
	
    }
	
 if (receivedCommand == "OFF") {
     //sendTelegram("bot1", "Clima zona notte SPENTO")
	 //condi_notte_on_off.postUpdate("OFF")
	 condi_notte_state.postUpdate( SPENTO )
    }
 	
end

finally resolved !! thanks to all for the help!! :partying_face:

rule "feedback condizionatore notte status"

when
   Item condi_notte_on_off changed
then 

 if (condi_notte_on_off.state.toString  == "ON" ){
      sendTelegram("bot1", "Clima zona notte ACCESO")
	//condi_notte_on_off.postUpdate("ON")
	condi_notte_state.postUpdate( 10 )
	
	
    }
	
 if (condi_notte_on_off.state.toString  == "OFF" ) {
     sendTelegram("bot1", "Clima zona notte SPENTO")
	 //condi_notte_on_off.postUpdate("OFF")
	 condi_notte_state.postUpdate( 9 )
    }
 	
end
1 Like