Page 2 of 3
Re: LUA script for Sony Bravia TV
Posted: Wednesday 08 June 2016 20:33
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.
Re: LUA script for Sony Bravia TV
Posted: Wednesday 08 June 2016 20:51
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
Re: LUA script for Sony Bravia TV
Posted: Thursday 09 June 2016 13:55
by rickwilleme
I got the Power Management working on my Sony tv as well.
Thanks!
Re: LUA script for Sony Bravia TV
Posted: Friday 17 June 2016 10:54
by rickwilleme
Still very happy with the current integration!
Any clue if volume control will also be an option?
Re: LUA script for Sony Bravia TV
Posted: Saturday 02 July 2016 21:54
by maomanna
I have the status script working,
but how can I switch it off/on or use the TV in blockly's?
Re: LUA script for Sony Bravia TV
Posted: Sunday 24 July 2016 1:21
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.
Re: LUA script for Sony Bravia TV
Posted: Sunday 02 October 2016 17:44
by M3leee
Thanks guys! Script is working great!
Re: LUA script for Sony Bravia TV
Posted: Wednesday 05 October 2016 16:19
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?
Re: LUA script for Sony Bravia TV
Posted: Thursday 06 October 2016 7:07
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.
Re: LUA script for Sony Bravia TV
Posted: Thursday 06 October 2016 21:32
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?
Re: LUA script for Sony Bravia TV
Posted: Monday 21 November 2016 10:22
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?
Re: LUA script for Sony Bravia TV
Posted: Friday 09 December 2016 21:24
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?
Re: LUA script for Sony Bravia TV
Posted: Sunday 08 January 2017 20:27
by Persisto
@ StefanPuntNL Thanks for that, works perfectly
Re: LUA script for Sony Bravia TV
Posted: Wednesday 25 January 2017 23:25
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
Re: LUA script for Sony Bravia TV
Posted: Monday 01 May 2017 23:35
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?
Re: LUA script for Sony Bravia TV
Posted: Tuesday 02 May 2017 0:19
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.
Re: LUA script for Sony Bravia TV
Posted: Tuesday 02 May 2017 21:03
by vgr2
Hello G3rard, works fine on my kd-55x9005b. Will it be possible to read out the channel list from TV?
Re: LUA script for Sony Bravia TV
Posted: Tuesday 02 May 2017 21:16
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?
Re: LUA script for Sony Bravia TV
Posted: Tuesday 02 May 2017 21:37
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.
LUA script for Sony Bravia TV
Posted: Tuesday 02 May 2017 22:08
by G3rard
Good to hear it's working
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.