String to Switch Type Conversion

  • Platform information:
    • openHAB version: 3.4.1
	Time cron "*/60 * * * * ?"
if (Nest_Away.state == "HOME") {

	val String statePlug3 = executeCommandLine(Duration.ofSeconds(5), "bash", "/etc/openhab/scripts/ecoplugs/scripts/");


This rule used to work in OH2.4.

However in OH3
I get this error now.

2023-01-27 13:51:01.371 [WARN ] [b.core.model.script.actions.BusEvent] - Cannot convert 'ON' to a state type which item 'EcoPlug_3_Switch' accepts: [OnOffType, UnDefType].

The script gets a state of “ON” or “OFF”
I haven’t been able to find the solution to properly convert the string to the correct switch type

Does the return from the script include a newline?


is not the same as


You could probably add a trim to the end to remove the newline if it’s there and that’s the problem.


But it’s always a good idea to log things out when something doesn’t work instead of just blindly using them. What is statePlug3 set to?

1 Like

Thanks So much. Adding .trim fixed it.
I guess for some reason it had a return. It’s odd how in OH2.4 it just worked.

In OH 2.4 the newline was ignored.