i try with a string transmitted serially via USB for example “Light_GaesteZ_:OFF;Light_SleepZ_General_:OFF;Light_SleepZ_Cabinet_:OFF”.
to report the status of the light switches.
For example, I have the switch item:
switch light_guestroom_general “light guestroom”
How can I read the feedback from the Arduino and change the switch status e.g. at “Licht_GaesteZ_:ON” light symbol is on and at “Licht_GaesteZ_:OFF” light symbol is off.
yes, i downloaded that and released the serial ports in the files of openhab.
String Arduino “Arduino [%s]” (arduino) {serial="/dev/ttyACM0"}
The response of e.g. “Licht_GaesteZ_” will be displayed despite the error:
“2019-12-28 21:32:02.381 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert ‘’ to a state type which item ‘Light_Guestroom_General’ accepts: [OnOffType, UnDefType].”.
is shown as “ON” or “OFF”, but not, if I query the next switch e.g. “Light_Bedroom_General_”, then only the first one is recognized, but both are shown in the .log with the same error:
"2019-12-28 21:32:02.381 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert ‘’ to a state type which item ‘Light_Bedroom_General’ accepts: [OnOffType, UnDefType].
2019-12-28 21:32:02.394 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert ‘’ to a state type which item ‘Light_Bedroom_General’ accepts: [OnOffType, UnDefType].
rule “Read Arduino”
when
Item Arduino received update
then
var String ArduinoUpdate = Arduino.state.toString.trim
var int LightGuestroomGeneralStartAt = ArduinoUpdate.indexOf(“Light_GaesteZ_:”) + “Light_GaesteZ_:”.length
var String LightGuestroomGeneral = ArduinoUpdate.mid(LightGuestroomGeneralStart On, ArduinoUpdate.indexOf(’;’)-LightGuestroomGeneralStart On)
var int LightSleeping_roomGeneralStartAt = ArduinoUpdate.indexOf(“Light_Sleeping_room_General_:”) + “Light_Sleeping_room_General_:”.length
var String LightBedroomGeneral = ArduinoUpdate.mid(LightBedroomGeneralStart On, ArduinoUpdate.indexOf(’;’)-LightBedroomGeneralStart On)
i’ve been busy with the REGEX variant for hours now and have been able to filter out the individual words, but i can manage to convert the individual words into the corresponding commands.
For example I filtered out the “;” with the following:
[\w]+[\w]
Now I don’t know how to proceed with this or how I could assign this to the individual items.
I would like to ask again if I really have to convert the words in the string into an integer to process them further or if I can filter out the words with “REGEX” as shown above and process them further.
…I still can’t get any further, and I’ve spent many hours…
One looked very simple and feasible, but again I can’t get it to work with more than one query…
rule “Arduino on update”
when
Item Arduino received update
then
// var String ArduinoUpdate = Arduino.state.toString.trim
ArduinoUpdate = ArduinoUpdate + Arduino.state.toString.trim
if (ArduinoUpdate.contains(";")) {
if (ArduinoUpdate.contains("Licht_GaesteZ")) {
postUpdate(Licht_Gaestezimmer_Allgemein, if(ArduinoUpdate.contains("ON")) ON else OFF)
}
if (ArduinoUpdate.contains("Licht_SchlafZ_Allgemein")) {
postUpdate(Licht_Schlafzimmer_Allgemein, if(ArduinoUpdate.contains("ON")) ON else OFF)
}
ArduinoUpdate = ""
}