Added code from openhab work