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
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
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.
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
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
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