LUA script for Sony Bravia TV

User avatar
G3rard
Posts: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: LUA script for Sony Bravia TV

Post by G3rard » Wednesday 08 June 2016 20:33

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.
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

piotr
Posts: 30
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 » Wednesday 08 June 2016 20:51

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: 68
Joined: Wednesday 16 December 2015 16:25
Target OS: Raspberry Pi
Domoticz version: 3.6792
Location: Landgraaf, The Netherlands
Contact:

Re: LUA script for Sony Bravia TV

Post by rickwilleme » Thursday 09 June 2016 13:55

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: 68
Joined: Wednesday 16 December 2015 16:25
Target OS: Raspberry Pi
Domoticz version: 3.6792
Location: Landgraaf, The Netherlands
Contact:

Re: LUA script for Sony Bravia TV

Post by rickwilleme » Friday 17 June 2016 10:54

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: 108
Joined: Monday 30 November 2015 17:21
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: LUA script for Sony Bravia TV

Post by maomanna » Saturday 02 July 2016 21:54

I have the status script working,
but how can I switch it off/on or use the TV in blockly's?

Sergio
Posts: 54
Joined: Friday 12 December 2014 14:25
Target OS: Raspberry Pi
Domoticz version: 3.9639
Location: Spain
Contact:

Re: LUA script for Sony Bravia TV

Post by Sergio » Sunday 24 July 2016 1:21

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 » Sunday 02 October 2016 17:44

Thanks guys! Script is working great!

Tharland
Posts: 7
Joined: Wednesday 05 October 2016 16:02
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: LUA script for Sony Bravia TV

Post by Tharland » Wednesday 05 October 2016 16:19

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 10:29
Target OS: Linux
Domoticz version:
Contact:

Re: LUA script for Sony Bravia TV

Post by electronicsguy » Thursday 06 October 2016 7:07

@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
Domoticz version:
Contact:

Re: LUA script for Sony Bravia TV

Post by Tharland » Thursday 06 October 2016 21:32

@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: 108
Joined: Monday 30 November 2015 17:21
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: LUA script for Sony Bravia TV

Post by maomanna » Monday 21 November 2016 11:22

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: 75
Joined: Wednesday 18 June 2014 23:57
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands
Contact:

Re: LUA script for Sony Bravia TV

Post by Slayer007 » Friday 09 December 2016 22:24

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: 20
Joined: Wednesday 03 February 2016 22:10
Target OS: Linux
Domoticz version: 2.4386
Location: Plailly France
Contact:

Re: LUA script for Sony Bravia TV

Post by Persisto » Sunday 08 January 2017 21:27

@ 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: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: LUA script for Sony Bravia TV

Post by G3rard » Thursday 26 January 2017 0:25

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
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

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 » Monday 01 May 2017 23:35

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: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: LUA script for Sony Bravia TV

Post by G3rard » Tuesday 02 May 2017 0:19

@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.
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

vgr2
Posts: 91
Joined: Monday 29 August 2016 12:02
Target OS: -
Domoticz version:
Contact:

Re: LUA script for Sony Bravia TV

Post by vgr2 » Tuesday 02 May 2017 21:03

Hello G3rard, works fine on my kd-55x9005b. Will it be possible to read out the channel list from TV?

User avatar
G3rard
Posts: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: LUA script for Sony Bravia TV

Post by G3rard » Tuesday 02 May 2017 21:16

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?
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

vgr2
Posts: 91
Joined: Monday 29 August 2016 12:02
Target OS: -
Domoticz version:
Contact:

Re: LUA script for Sony Bravia TV

Post by vgr2 » Tuesday 02 May 2017 21:37

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: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

LUA script for Sony Bravia TV

Post by G3rard » Tuesday 02 May 2017 22:08

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.
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest