[SOLVED] SendCommand(Variable.state as DecimalType)

When kodi is playing a video it sets the variable living room lights to 30. even if its light out i dont want it to do anything with that. when it gets dark and motion is detected, i’d like to set the dimmer to 30 as set before.
it does sent the command but i think the 30 is a string rather then a number could this be possible?

item:

 Number Living_Room_Main
    Number Living_Room_Cube
    Dimmer Living_Room_Cube_Dimmer "Cube Light Livingroom" <light> {channel="zwave:device:a4abc26e:node4:switch_dimmer"}
    Dimmer Living_Room_Dimmer "Living Room Dimmer Main" <light> {channel="zwave:device:a4abc26e:node11:switch_dimmer"}

rules:

rule "kodi paused"
when
    Item My_Item changed
then
 if(My_Item.state== 1)
    {logInfo('Kodi','kodi is playing ')
    Living_Room_Main.sendCommand(30)
    Living_Room_Cube.sendCommand(30)
    if ((Living_Room_Lux.state as DecimalType)<80){
        Living_Room_Cube_Dimmer.sendCommand("30")
        Living_Room_Dimmer.sendCommand("20")
        }
    }

if(My_Item.state==2) {
            logInfo('Kodi','Kodi Stopped')
            Living_Room_Main.sendCommand("60")
            Living_Room_Cube.sendCommand("40")
            if ((Living_Room_Lux.state as DecimalType)<80){
        Living_Room_Cube_Dimmer.sendCommand("40")
        Living_Room_Dimmer.sendCommand("55")
        }
        }
 end

rule "Livingroom Lights on by motion"
	when
	Item Living_Room_Motion changed to ON
	then
	if ((Living_Room_Lux.state as DecimalType)<80){
        Living_Room_Cube_Dimmer.sendCommand(Living_Room_Cube.state as DecimalType)
        Living_Room_Dimmer.sendCommand(Living_Room_Main.state as DecimalType)
	    }
	end

log:

2018-06-12 21:54:12.670 [vent.ItemStateChangedEvent] - zwave_serial_zstick_a4abc26e_serial_sof changed from 20173 to 20174

2018-06-12 21:54:12.681 [vent.ItemStateChangedEvent] - zwave_device_a4abc26e_node3_meter_current changed from 1.83 to 1.22

2018-06-12 21:54:16.804 [ome.event.ItemCommandEvent] - Item 'Living_Room_Motion' received command ON

2018-06-12 21:54:16.814 [vent.ItemStateChangedEvent] - Living_Room_Motion changed from OFF to ON

2018-06-12 21:54:16.843 [ome.event.ItemCommandEvent] - Item 'Living_Room_Occu' received command ON

2018-06-12 21:54:16.854 [ome.event.ItemCommandEvent] - Item 'Living_Room_Cube_Dimmer' received command 40

2018-06-12 21:54:16.864 [ome.event.ItemCommandEvent] - Item 'Living_Room_Dimmer' received command 60

The last log item Received 60, yeah it doesn’t respond to that at all… what am i doing wrong?

Never mind i figured it out. there was a problem in my setting rule.

Can you post your solution, please?

I ended up not really fixing the variable issue, more replacing it. i put the If statement of the kodi state 1 OR 2 in the first livingroom motion rule

rule "Livingroom Lights on by motion"
	when
	Item Living_Room_Motion changed to ON
	then
	if ((Living_Room_Lux.state as DecimalType)<80){
             if(My_Item.state== 1){
			    if ((Living_Room_Lux.state as DecimalType)<80){
			        Living_Room_Cube_Dimmer.sendCommand("30")
			        Living_Room_Dimmer.sendCommand("20")}
			        }
			    }

			if(My_Item.state==2) {
			            logInfo('Kodi','Kodi Stopped')
			            if ((Living_Room_Lux.state as DecimalType)<80){
			            Living_Room_Cube_Dimmer.sendCommand("40")
			            Living_Room_Dimmer.sendCommand("55")
			             }
			        }
	end

So instead of trying to set the lights to the variable value, i just check if kodi is playing, and coppied the value. it’s not ideal. but it works till i can find a real solution. any input is welcome.

No, MyDimmerItem.sendCommand() will definitely work flawless with numerical values.
For instance,

Living_Room_Cube_Dimmer.sendCommand(40)

should work.
Instead of DecimalType, please use Number:

Living_Room_Cube_Dimmer.sendCommand(Living_Room_Cube.state as Number)

But ensure that Living_Room_Cube.state is of Type Number:

if(Living_Room_Cube.state instanceof Number)

When using DecimalType, openHAB has two options, either to use it as integer or float value (would be possible to set this by using

(Living_Room_Cube.state as DecimalType).intValue

This: (Living_Room_Lux.state as DecimalType < 80) should be marked as an error when using VSCode with openHAB plugin.

1 Like

@Udo_Hartmann
I use Number type almost everywhere now