Samsung tv binding with openhab2 and knx


(Yasser) #1

Can someone help me to write the suitable code (rule) to make the knx system to control the Samsung TV as follows : when the group address (for example 1/3/6) have a signal from sensor the TV should view the HDMI input 2 for a 10 sec then go back to same status at HDMI input 1…


(Udo Hartmann) #2

In general, you will need some items:

Switch MyknxSensor "knx Sensor [$s]" { knx="1/3/6" }
String MySamsungSourceName "TV Source [$s]" { channel="samsungtv:tv:livingroom:sourceName" }
Number MySamsungSourceId "TV Source [$d]" { channel="samsungtv:tv:livingroom:sourceId" }
String MySamsungKey "TV Key [$s]" { channel="samsungtv:tv:livingroom:keyCode" }

Of course you need a working knx1 binding and a working samsungTV2 binding, too.

And now rule to do the ‘magic’ switching:

var Timer tTvSwitch = null

rule "auto switch tv"
when
    Item MyknxSensor received command
then
    if (received command == ON) {
        var number oldsource=MySamsungSourceId.state as DecimalType
        MySamsungSourceId.sendCommand(2)                            //2 would be the number which refers to hdmi2
        MySamsungSourceName.sendCommand("hdmi2")                    // only one of the three rows
        MySamsungKey.sendCommand("KEY_HDMI2")                       // is to be used, Key should work
        if(tTvSwitch != null) {
            tTvSwitch.cancel
            tTvSwitch = nulll
        }
        tTvSwitch = createTimer(now.plusSeconds(10)) [|
            MySamsungSourceId.sendCommand(oldsource)                // set to last source
            MySamsungSourceName.sendCommand("hdmi1")                // only one of the three rows
            MySamsungKey.sendCommand("KEY_HDMI1")                   // is to be used, Key should work
        ]
    }
end

I don’t own a samsung tv, so, there are some things I don’t know:

  1. Maybe sourceName is read only, and maybe sourceId is read only, too, you would have to try out :slight_smile:
  2. If sourceId is read/write, I would prefer this way, because this would ensure the last source is used after action. To find the correct number for hdmi2, just switch to hdmi2 and take a look at the value of MySamsungSourceId.
    You could do something similar of course with sourceName, and even Key feature will work, but in question of Key you would have to use some sort of list.
  3. for key commands, I did look up those keys in SamsungTV1 binding, as this is not mentioned, I hope, this is correct :wink:

To prettify the rule, you could ensure, that the tv is switched on.


(Yasser) #3

Thanks :slight_smile:


(Yasser) #4

when installing samsung TV and knx bindings from paper UI, of course i modified the openhab.cfg and knx.cfg, Do I need to copy any files to make this working… or just installation from paper UI…?

thanks for advice…