Trigger in a rule from Player item type. LG webOS binding

Is it possible to trigger a rule using the media Player item type?

I can’t get the following to work:

rule "TV play-pause rule"

when 
	Item TVPlayer changed to PLAY
then
	logInfo("TV player state:", TVPlayer.state.toString)
         ....do other stuff..
end

I can trigger a rule from something else and then read the player item state within the rule but I can’t trigger the rule from the change of state of this item.
I also tried changed and received command on their own.

Any ideas?

There’s a typo in your logInfo, but maybe just copy error.

changed and command triggers are wildly different, no good trying things at random.

Does your rules file load? (see openhab.log)
What do you see about the TVPlayer Item in events.log? (changes and commands will be recorded there)

Yes, that was a typo. Fixed now. The rule does load.

Trying things at random is okay if all else fails. Then, when it works you can work out what you did wrong.
It’s a massively inefficient way of doing things though!

Yes, I ought to check the logs.

Nothing at all although the rule does load.

However, there is progress: I wrote another rule with a simple switch which when operated, alternates the Player item state between PAUSE and PLAY. This does cause the first rule to trigger.

So the only problem I have is being able to use the Player item state to trigger a rule when the state is changed outside of openHAB (with the TV remote, for example).

Okay, so if you see nothing for this Item in events.log there is nothing for rules to trigger from. No incoming status, nothing from openHAB sending it commands.

I suppose you are expecting some update from a device? Next step is look at Item binding.

Whoops. Player is a Write-only channel (so I can read it bit not trigger on it).

Apart from constantly reading the state of that channel, which I wouldn’t want to do, does any know of another way of reading the play/pause state so could, for example, dim the lights when play is pressed and used and turn up the brightness when pause is pressed?

But you cannot do that if it write only …

The key question is pressed where.
You can of course monitor commands issued from openHAB from UI or rules.
There does not appear to be any way to get feedback from the actual device if anything else alters it.

It’s Write only according to the binding docs (which I should have checked first) but, as I wrote before, you can read it, and use it as a rule trigger, if the state is changed via openHAB.

What you cannot do is use it as a trigger when the state is changed via a non-openHAB source such as the TV remote control, which is what I wanted to do.

1 Like

I wondered if the binding might be enhanced to listen for this status from TV, but it looks like HA has the same issue, so I guess it’s a webOS limitation

A possible solution would be to have a separate IR listener using a uController to decode the IR signals from the TV remote and send these via MQTT to openHAB to indicate button presses.

@sprehn : As the binding is your creation, I’m sure you know whether the Player state really is only writeable and not readable or whether you chose to just be able to make it write only.
Which is it? Thanks.

1 Like

There is no subscriber mechanism for player state in the TVs API to my knowledge. That is why the binding will not notice change in state when initiated by TV. API is also not documented. if anyone finds documentation on how to do it we could implement it.

1 Like

Thanks for the reply and for looking into it.
I’m pretty ignorant to all of this so excuse my novice question but is it possible to know the player state by subscribing to the remote control key-presses rather than the actual player state?

Is it an infrared handset? You can get gubbins to eavesdrop on that, I believe. It would not tell you what the TV is doing, but only what it is has been asked to do.

1 Like

I had already considered that:

Thanks for the links. I was going to do it the way I wrote in my post but if someone’s already done it…

Have read this posting+replies with much interest as this is exactly what I need (triggering rules based on PLAY/PAUSE state of my new LG Webos tv). In the previous setup this was very easy to do with an external chromecast (state changes showed up in logfiles and allowed to me to create rules). I find it very disappointing that this should not be possible with an otherwise fantastic TV, but as there is mention of intercepting IR signals seems that all kinds of routes have been explored already.

Anyone figured this out in the meantime? I was thinking whether it would be possible to measure flowrate of network traffic rate (in Kb/s) and use this as way of detecting if the tv is PLAYing or PAUSEd?

A TV will continue to download chunks of data unit it’s data buffer is full so relying on network traffic cessation to indicate a PAUSE would not be reliable as there would be a variable time-lag.