LUA script for Sony Bravia TV

Moderator: leecollings

User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: LUA script for Sony Bravia TV

Post by G3rard »

The script_time_tvstatus.lua is time script which you seem to use as a device script, as your first post says script_device_tv.lua. Check the wiki for the differences and how to use it.
Not using Domoticz anymore
piotr
Posts: 26
Joined: Monday 15 July 2013 8:17
Target OS: Linux
Domoticz version: Beta
Location: Drenthe
Contact:

Re: LUA script for Sony Bravia TV

Post by piotr »

I understand the difference and I use both scripts with the correct name. They work ok, it just logs an error:

Code: Select all

2016-06-08 20:48:00.485 LUA: TV ping success
2016-06-08 20:48:00.528 LUA: TV says it is standby
2016-06-08 20:48:00.528 LUA: TV standby, status is OFF, so do nothing.
and

Code: Select all

2016-06-08 20:48:01.088 Error: EventSystem: Lua script /home/user/domoticz/scripts/lua/script_device_tv.lua did not return a commandArray
rickwilleme
Posts: 53
Joined: Wednesday 16 December 2015 15:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.6792
Location: Landgraaf, The Netherlands
Contact:

Re: LUA script for Sony Bravia TV

Post by rickwilleme »

I got the Power Management working on my Sony tv as well.
Thanks! :mrgreen:
Raspberry Pi ~ Fibaro Dimmer (Z-Wave) ~ Several KAKU switches and dimmers (433 MHz) ~ Amazon Echo ~ Somfy RTS ~ Sony TV ~ Kodi/XBMC ~ Essent E-Thermostaat (ICY) ~ Cresta thermostat ~ Wundermap Weather ~ Smoke detectors
rickwilleme
Posts: 53
Joined: Wednesday 16 December 2015 15:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.6792
Location: Landgraaf, The Netherlands
Contact:

Re: LUA script for Sony Bravia TV

Post by rickwilleme »

Still very happy with the current integration!
Any clue if volume control will also be an option?
Raspberry Pi ~ Fibaro Dimmer (Z-Wave) ~ Several KAKU switches and dimmers (433 MHz) ~ Amazon Echo ~ Somfy RTS ~ Sony TV ~ Kodi/XBMC ~ Essent E-Thermostaat (ICY) ~ Cresta thermostat ~ Wundermap Weather ~ Smoke detectors
maomanna
Posts: 94
Joined: Monday 30 November 2015 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: LUA script for Sony Bravia TV

Post by maomanna »

I have the status script working,
but how can I switch it off/on or use the TV in blockly's?
Sergio
Posts: 39
Joined: Friday 12 December 2014 13:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: LUA script for Sony Bravia TV

Post by Sergio »

So after all the changes, the script_device_tv.lua should look like this:

Code: Select all

commandArray = {}

if(devicechanged['TV']) then
  if (devicechanged['TV'] == 'On') then
    if(uservariables['TVOnlyStatusUpdate'] == 1) then
       print('TV status update received (ON), resetting user variable.')
       commandArray['Variable:TVOnlyStatusUpdate'] = '0'
    else
       runcommand = '/home/pi/domoticz/scripts/tvremote.sh PowerOn'
       os.execute(runcommand)
       print('TV got wake up call')
    end    
  end
  if (devicechanged['TV'] == 'Off') then
    if(uservariables['TVOnlyStatusUpdate'] == 1) then
       print('TV status update received (OFF), resetting user variable.')
       commandArray['Variable:TVOnlyStatusUpdate'] = '0'
    else
       runcommand = '/home/pi/domoticz/scripts/tvremote.sh PowerOff'
       response = os.execute(runcommand)
       if response then
          print('TV goes sleepy sleep')
       else
          print('TV not in the mood for sleepy sleep')
       end
    end 
  end
end

return commandArray
Nice work, guys! Thank you.
M3leee
Posts: 1
Joined: Monday 26 September 2016 11:56
Target OS: -
Domoticz version:
Contact:

Re: LUA script for Sony Bravia TV

Post by M3leee »

Thanks guys! Script is working great!
Tharland
Posts: 7
Joined: Wednesday 05 October 2016 16:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: LUA script for Sony Bravia TV

Post by Tharland »

Prerequisites:
  • Create a virtual switch (On/Off) named "TV"
  • Create a user variable (integer) named "TVOnlyStatusUpdate", with value 0
  • Install etherwake (sudo apt-get install etherwake)
  • Enable remote start on your TV: [Settings] → [Network] → [Home Network Setup] → [Remote Start] → [On]
  • Enable pre-shared key on your TV: [Settings] → [Network] → [Home Network Setup] → [IP Control] → [Authentication] → [Normal and Pre-Shared Key]
  • Set pre-shared key on your TV: [Settings] → [Network] → [Home Network Setup] → [IP Control] → [Pre-Shared Key] → [sony]
  • Give your TV a static IP address, or make a DHCP reservation for a specific IP address in your router.
  • Determine the MAC address of your TV: [Settings] → [Network] → [Network Setup] → [View Network Status]
The virtual switch will, obviously, be used in the interface to control the device and see the status. The user variable is to determine whether the device has been switched on or off via the timed script. If that is the case, the device script doesn't have to actually switch on/off the device. In that case only the status in Domoticz has to be updated.



1: script_time_tvstatus.lua

Code: Select all

function getPowerStatus()
  local url = 'http://10.101.0.50/sony/system'
  local headername = 'X-Auth-PSK'
  local headervalue = 'sony'
  local jsonbodygetstatus = '{\\"id\\":2,\\"method\\":\\"getPowerStatus\\",\\"version\\":\\"1.0\\",\\"params\\":[]}'

  local runcommand = 'curl -v -H \"Content-Type:application/json\" -H \"' .. headername .. ':' .. headervalue .. '\" -d \"' .. jsonbodygetstatus .. '\" ' .. url .. ''

  local h=io.popen(runcommand)
  local response=h:read("*a")
  h:close()

  if string.find(response, '{"status":"active"}') then
    return 'active'
  elseif string.find(response, '{"status":"standby"}') then
    return 'standby'
  else
    return 'unkown'
  end
end

commandArray = {}

ping_success=os.execute('ping -c1 10.101.0.50')
if (ping_success) then
   print('TV ping success')
   powerstatus=getPowerStatus()
   print('TV says it is ' .. powerstatus)
   if(powerstatus == 'active') then
      if(otherdevices['TV'] == 'Off') then
         print('TV active, but status is OFF, so update to ON.')
         commandArray['Variable:TVOnlyStatusUpdate'] = '1'
         commandArray['TV'] = 'On'
      else
         print('TV active, status is ON, so do nothing.')
      end
   elseif(powerstatus == 'standby') then
      if(otherdevices['TV'] == 'On') then
         print('TV standby, but status is ON, so update to OFF.')
         commandArray['Variable:TVOnlyStatusUpdate'] = '1'
         commandArray['TV'] = 'Off'
      else
         print('TV standby, status is OFF, so do nothing.')
      end
   else
      print('TV in unknown power status, doing nothing...')
   end
else
   print("TV ping fail")
   if(otherdevices['TV'] == 'On') then
      print('TV current status here is ON, so update status to OFF.')
      commandArray['Variable:TVOnlyStatusUpdate'] = '1'
      commandArray['TV']='Off'
   else
      print('TV current status here is OFF, so do nothing.')      
   end
end

return commandArray

For starters i new to domoticz so bare with me. What i want start with is to get a indication if the tv is on or not, i have a sony bravia KDL55HX 823, and i cant set pre-sharedkey neither do i have the ipconfig menu. But in my network i can access and ping the ip for the tv so i think i can get a indication if its on or off. But how should the cript look like'? And how do i use this script? I have followed the steps above but cant get it to work.

EDIT: I have fixed if i ping i get a status that its on and off when i shut down the wifi on the tv. But the standby function.. how do i get this to work?
electronicsguy
Posts: 1
Joined: Friday 29 January 2016 9:29
Target OS: Linux
Domoticz version:
Contact:

Re: LUA script for Sony Bravia TV

Post by electronicsguy »

@tharland - I think your TV doesn't support the network remote function. Similar to my TV, Sony KLV series. They options of PSK and others are missing in the TV's network menu. I can also ping but not actually control the TV with the scripts. My TV is also not listed (by Sony itself) as being compatible with their "sideview" app. So I think it's futile to use these script on non-compatible TVs.
Tharland
Posts: 7
Joined: Wednesday 05 October 2016 16:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: LUA script for Sony Bravia TV

Post by Tharland »

@electronicsguy I have a Sony TV with options for side view that is set to "on". I can control the tv with app for smartphone. But this isn't maybe the same?
maomanna
Posts: 94
Joined: Monday 30 November 2015 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: LUA script for Sony Bravia TV

Post by maomanna »

The Sony bravia series without android have a notification function.
I cannot find the command to send a notification to the TV.

This can be usefull to use PiP with securitycamera's or just a notification when the doorbell/windowsensor is triggered.

Anyone know how to do this?
Slayer007
Posts: 29
Joined: Wednesday 18 June 2014 23:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: LUA script for Sony Bravia TV

Post by Slayer007 »

I own a Sony XD9305, but I can't get the status or lua-scripts to work. What am i doing wrong? In domoticz I get the error: lua:5: unexpected symbol near char(194).

What does that mean?
Persisto
Posts: 18
Joined: Wednesday 03 February 2016 21:10
Target OS: Linux
Domoticz version: 2.4386
Location: Plailly France
Contact:

Re: LUA script for Sony Bravia TV

Post by Persisto »

@ StefanPuntNL Thanks for that, works perfectly
Plailly France
X10 Marmitek + Ebode for lights and blinds + CM15
mochad
Domoticz, Domoticz Lite, Geofence
Raspberry Pi III
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: LUA script for Sony Bravia TV

Post by G3rard »

Currently working on a Python plugin for the Sony Bravia TV. See the link below for some more information.
http://www.domoticz.com/forum/viewtopic ... 65&t=16910
Not using Domoticz anymore
CodeFestus
Posts: 1
Joined: Monday 01 May 2017 23:30
Target OS: Linux
Domoticz version:
Contact:

Re: LUA script for Sony Bravia TV

Post by CodeFestus »

My 46EX523 doesn't have:
[Settings] → [Network] → [Home Network Setup] → [IP Control]

It does work with SlideView (goes through a handshake to register).
Has anyone figured out that protocol?
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: LUA script for Sony Bravia TV

Post by G3rard »

@CodeFestus, have a look at viewtopic.php?f=65&t=16910&start=20#p128866.
You should get this working with the use of a cookie.
Not using Domoticz anymore
vgr2
Posts: 71
Joined: Monday 29 August 2016 12:02
Target OS: -
Domoticz version:
Contact:

Re: LUA script for Sony Bravia TV

Post by vgr2 »

Hello G3rard, works fine on my kd-55x9005b. Will it be possible to read out the channel list from TV?
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: LUA script for Sony Bravia TV

Post by G3rard »

You mean the Sony Bravia Python plugin works fine with your TV?
And it is possible to read out the channel list from the TV, but how do you want to use it in Domoticz?
Not using Domoticz anymore
vgr2
Posts: 71
Joined: Monday 29 August 2016 12:02
Target OS: -
Domoticz version:
Contact:

Re: LUA script for Sony Bravia TV

Post by vgr2 »

Yes I mean the Python plugin. Sorry i did the replay on wrong topic. Yes and read out the cannel list into your channel plugin...maybe more than 9 channels.
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

LUA script for Sony Bravia TV

Post by G3rard »

Good to hear it's working Image
The selector switch in Domoticz only supports 10 values, so it's not possible to show all channels.
I am currently testing the remote control from Domoticz, which gives the option to show the EPG and choose a channel.
Edit: see viewtopic.php?f=65&t=16910&p=132330#p132330 for latest version with remote control support.
Not using Domoticz anymore
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest