thisisIO
(Michael)
January 17, 2019, 10:38am
1
Hello,
i have a Arduino that send commands via serial port to OH.
Like this
2019-01-17 11:33:03.982 [vent.ItemStateChangedEvent] - Arduino changed from 44100608unit1off to 44100608unit1on
I would like to catch them und use them in rules with CASE.
I wrote the rule, but ir do not work
rule "Arduino"
when
Item Arduino changed
then
switch(Arduino.state.toString) {
case "44100608unit1on": {
logInfo("arduino.rules", "Arduino State changed: "+ Arduino.state + "")
}
case "44100608unit1off": {
logInfo("arduino.rules", "Arduino State changed: "+ Arduino.state + "")
}
}
end
It do not goes inside case. I thnig problem is here
switch(Arduino.state.toString)
What have i made wrong?
Thanks a lot!
vzorglub
(Vincent Regaud)
January 17, 2019, 10:41am
2
See:
https://www.eclipse.org/xtend/documentation/203_xtend_expressions.html#switch-expression
rule "Arduino"
when
Item Arduino changed
then
switch Arduino.state.toString {
case "44100608unit1on": {
logInfo("arduino.rules", "Arduino State changed: "+ Arduino.state + "")
}
case "44100608unit1off": {
logInfo("arduino.rules", "Arduino State changed: "+ Arduino.state + "")
}
}
end
1 Like
thisisIO
(Michael)
January 17, 2019, 10:44am
3
vzorglub:
rule “Arduino” when Item Arduino changed then switch Arduino.state.toString { case “44100608unit1on”: { logInfo(“arduino.rules”, "Arduino State changed: "+ Arduino.state + “”) } case “44100608unit1off”: { logInfo(“arduino.rules”, "Arduino State changed: "+ Arduino.state + “”) } } end
Thanks for quick answer!
But do not work(((
Maybe it is not a string?
Maybe you do not receive what you think you receive. Add a log statement before the switch to log Arduino.state.toString
.
1 Like
Are you sure that there are not leading/trailing spaces? An easy way to check is to put the printed state between brackets:
logInfo("arduino.rules", "Arduino State changed: ["+ Arduino.state + "]")
2 Likes
rossko57
(Rossko57)
January 17, 2019, 10:54am
7
rule "Arduino"
when
Item Arduino changed
then
switch Arduino.state.toString {
case "44100608unit1on": {
logInfo("arduino.rules", "Arduino State changed: "+ Arduino.state + "")
}
case "44100608unit1off": {
logInfo("arduino.rules", "Arduino State changed: "+ Arduino.state + "")
}
default: {
logInfo("arduino.rules", "Unexpected: "+ Arduino.state.toString + "")
}
}
end
1 Like
thisisIO
(Michael)
January 17, 2019, 10:56am
8
rossko57:
rule “Arduino” when Item Arduino changed then switch Arduino.state.toString { case “44100608unit1on”: { logInfo(“arduino.rules”, "Arduino State changed: "+ Arduino.state + “”) } case “44100608unit1off”: { logInfo(“arduino.rules”, "Arduino State changed: "+ Arduino.state + “”) } default: { logInfo(“arduino.rules”, "Unexpected: "+ Arduino.state + “”) } } end
Yes now i get Unexpected: 44100608unit1off
So what is wrong?
vzorglub
(Vincent Regaud)
January 17, 2019, 10:58am
9
Does the Arduino send a return character /n?
1 Like
rossko57
(Rossko57)
January 17, 2019, 10:58am
10
See @marcel_erkel suggestion
1 Like
thisisIO
(Michael)
January 17, 2019, 11:00am
11
Yes! Und how do i catch it?
this way do not work(((
case "44100608unit1on/n": {
thisisIO
(Michael)
January 17, 2019, 11:02am
12
vzorglub:
return character /n
This one Works:
case "44100608unit1on\r\n"
Thanks to all!
1 Like