jointSPACE - npe on /items list when TV switched off

Have observed HABPanel renders “connection lost” when Philips TV to which jointspace is configured is switched off.
Found out /rest/items/ is returning 500 error and NullPointeException.
When TV comes on, not immediately, but after a short while the error disapears.
Or if I rename jointspace items then /rest/items starts rendering and HABPanel is back in working state.
This is the smalles piece of jointspace items I had when observer error last time:

String CurrentSource "Source" {jointspace="POLL:source"}
Number SetSource "Set Source" {jointspace="1:source.tv, 2:source.hdmi1, 3:source.hdmi2, 4:source.hdmi3, 5:source.hdmiside"}

Using Openhab 2.1.0 release.
Is it the same for others? Are there any tricks how to overcome it? Thank you in advance!

The problem is that Phillips disables the network connection when the TV is in standby. And if the TV is no longer available, the Binding recognizes that and goes offline. As soon as you turn the TV back on, the network interface and the JointSpace start up again.
That’s why it is not possible to get the TV from standby via JointSpace. Unfortunately, it only works with IR or HDMI-CEC.

I understand this and no complaints (have idea of workaround - through chromecast, which uses cec).

My problem is that when TV is offline, jointspace brakes entire items list:(
/rest/items returns internal server error (500 and shows the npe) and HABPanel becomes unusable (since cant get any items). PaperUI is still working though (at least somting for plan B:)).

Controll your TV without the Binding …

http://jointspace.sourceforge.net/projectdata/documentation/jasonApi/1/doc/API.html

Example:

POST

curl -H "Content-Type: application/json" -X POST -d '{"current": 18}' http://ip-address:1925/1/audio/volume

GET

curl -H "Content-Type: application/json" -X GET  http://ip-address:1925/1/sources/current

Code to Extract source from Json response with jq - https://stedolan.github.io/jq/

curl -H "Content-Type: application/json" -s GET  http://10.10.80.120:1925/1/sources/current | jq -r '.id'

With the last Command and a Short BashScript you can observe the Source, with an on error Handling you can Switch your item to Standby/off if the API is not Online …

With a short NodeJS App you can controll the API with URLs …

Note: The command not works, if the TV is in Standby

Example to control the Volume with a Openhab Dimmer

#!/bin/sh
tv_max_volume=60
transform=`echo "scale=2; $tv_max_volume / 100 * $1" | bc | awk '{print int($1+0.5)}'`

curl -H "Content-Type: application/json" -X POST -d '{"current": '$transform} http://ip-address:1925/1/audio/volume
rule"Volume Philips TV"
when
  Item Volume_Philips_TV received update
then
  //Check if TV is Online eg. Ping the Device with Network Binding
  if (TV.state == ON){
    executeCommandLine("/etc/openhab2/scripts/tv_volume.sh " + Volume_Philips_TV.state)
  } 
  else{
    if (Volume_Philips_TV.state != 0) sendCommand.Volume_Philips_TV(0)
  }
end
1 Like

Thank You @ei_Gelb_Geek so much for your time and support! I managed to come up with something very similar, just using sendhttppostrequest(url,type,content) in the rule.
Plus Chromecast and say(“Hello”) in the PowerON rule to wake TV up :slight_smile:

Having done that, realized that network interface on TV somehow not very stable. It happens from time to time that TV is running, but not available on network. Will use this as temporary workaround until Santa receives my letter with Harmony Hub drawing :slight_smile:

1 Like

I optimized the Script a little bit :wink:

rule"Set Volume Philips TV"
when
  Item Volume_Philips_TV received update
then
  //Check if TV is Online eg. Ping the Device with Network Binding
  if (TV.state == ON){
    executeCommandLine("/etc/openhab2/scripts/tv_volume.sh " + "set_volume " + "Volume_Philips_TV " + Volume_Philips_TV.state)
  }
  else{
    if (Volume_Philips_TV.state != 0) sendCommand.Volume_Philips_TV(0)
  }
end

rule"Get Volume Philips TV at StartUp"
when
  Item TV changed from OFF to ON
then
    //Perhaps set a short Sleep ... give JointSpace time to start up ;-)
    //Try it for yourself ;-)
    executeCommandLine("/etc/openhab2/scripts/tv_volume.sh "+ "get_volume " + "Volume_Philips_TV")
end
#!/bin/sh

###################################
openhab_url="0.0.0.0"
openhab_port="8080"
tv_ipadresse="0.0.0.0"
###################################

case $1 in
  key)
    #Key => Standby , VolumeUp , VolumeDown , Mute , Back , Find , RedColour , GreenColour , YellowColour , BlueColour ,
    #       Home , Options , Dot , Digit0-9 , Info , CursorUp , CursorDown , CursorLeft , CursorRight , Confirm , Next ,
    #       Previous , Adjust , WatchTV , Viewmode , Teletext , Subtitle , ChannelStepUp , ChannelStepDown , Source ,
    #       PlayPause , Pause , FastForward , Stop , Rewind , Record , Online
    curl -H "Content-Type: application/json" -X POST -d '{"key": "'$2'"}' http://$tv_ipadresse:1925/1/input/key
    ;;
  set_source)
    #Sources => tv , sat , hdmi1 , hdmi2 , hdmi3 , hdmiside , ext1 , ypbpr , vga
    curl -H "Content-Type: application/json" -X POST -d '{"id": "'$2'"}' http://$tv_ipadresse:1925/1/sources/current
    ;;
  get_source)
    current_scource="$(curl -H "Content-Type: application/json" -s GET  http://$tv_ipadresse:1925/1/sources/current | jq -r '.id')"
    curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$current_scource" "http://$openhab_url:$openhab_port/rest/items/$2"
    ;;
  get_volume)
    tv_max_volume="$(curl -H "Content-Type: application/json" -s GET  http://$tv_ipadresse:1925/1/audio/volume | jq -r '.max')"
    volume_state="$(curl -H "Content-Type: application/json" -s GET  http://$tv_ipadresse:1925/1/audio/volume | jq -r '.current')"
    transform=`echo "scale=2; $tv_max_volume / 100 * $volume_state" | bc | awk '{print int($1+0.5)}'`
    curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$transform" "http://$openhab_url:$openhab_port/rest/items/$2"
    ;;
  set_volume)
    tv_max_volume="$(curl -H "Content-Type: application/json" -s GET  http://$tv_ipadresse:1925/1/audio/volume | jq -r '.max')"
    transform=`echo "scale=2; $tv_max_volume / 100 * $2" | bc | awk '{print int($1+0.5)}'`
    echo $transform
    curl -H "Content-Type: application/json" -s POST -d '{"current": '$transform} http://$tv_ipadresse:1925/1/audio/volume
    ;;
  get_mute)
    mute_state="$(curl -H "Content-Type: application/json" -s GET  http://$tv_ipadresse:1925/1/audio/volume | jq -r '.muted')"
    if [[ $mute_state == false ]]; then
      curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "OFF" "http://$openhab_url:$openhab_port/rest/items/$2"
    elif [[ $mute_state == true ]]; then
      curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "ON" "http://$openhab_url:$openhab_port/rest/items/$2"
    fi
    curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$mute_state" "http://$openhab_url:$openhab_port/rest/items/$2"
    ;;
  set_mute)
    #true/fasle
    curl -H "Content-Type: application/json" -X POST -d '{"muted": "'$2'"}' http://$tv_ipadresse:1925/1/audio/volume
    ;;
esac

Next step ist to control this and upcoming Script with NodeJS … :wink: