Set value or is value set?


i want to set a Color_Temp to Value 250 by

			sendCommand(ColorTemp, 250)

Does it make sense to check if this is already set like

		if (ColorTemp.state != 250) {
			sendCommand(ColorTemp, 250)

Which way produces more “load” to the system?

Thank you!

It rather depends what happens if the command is sent. At the minimum, it will produce a command event on the openHAB events bus, which has a more significant workload than if() in a rule. At worst, it generates unnecessary traffic on its way to a real device.

This smells a little bit like an XY Problem. Why are you concerned on the performance of something like this at all? Are you experiencing performance problems?

Assuming Rules DSL, ColorTemp.sendCommand(250) requires the least amount of work on openHAB. But unless you are doing hundreds of these calls per second, the difference between all three would be all but unmeasurable. If you are trying to solve some sort of performance problem, this isn’t going to fix it.

If you are not actually experiencing any sort of performance problem, then what is most important is what is easiest for you to read and understand? Your time and ability to read and understand your code is far more important than the CPU taking a couple extra milliseconds to process a command.