Ik ben bezig met een aantal integraties welke ook succesvol verlopen.
TV Sony Bravia 50W755C maar moet met alle Sony Bravia 2015/2016 modellen werken. (Ziet er naar uit dat alleen de Android TV's dit ondersteunen)
- Start Stop Netflix Spotify enz via het netwerk met de API
Windows 10 PC- WOL
- Remote shutdown met net rpc
NAS Thecus N52000XXX- WOL
- Remote shutdown met de Raspi via SSH naar de NAS
TV Sony Bravia 50W755C
Start Stop Netflix Spotify enz via het netwerk met de API
Domoticz Forum Sony Voornamelijk de post van noddy119 zie de link. Gekoppeld aan
Open Remote forum waar ik een combi van commando's heb kunnen vinden voor mijn TV, iets verder in de link staan ook in het groen commando's die kunnen werken.
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]
Enable Simple IP Control on your TV: [Settings] → [Network] → [Home Network Setup] → [IP Control] → [Simple IP Control] → [On]
Set pre-shared key on your TV: [Settings] → [Network] → [Home Network Setup] → [IP Control] → [Pre-Shared Key] → [yourkey]
Give your TV a static IP address, or make a DHCP reservation for a specific IP address in your router.
Het script, naam 'sony' bij mij:
#!/bin/bash
#Uncomment the following lines by removing the hash sign when your variables are not stored in profile.d
SonyBraviaPreSharedKey="sony" #Sony pre shared key, selected in your screen
SonyBraviaIP="192.168.1.130" #IP adress of you Sony TV
set -e
cd $(dirname $0)
if [ "$1" = "" ]; then
echo "Usage: $0 <COMMAND>"
exit 1
fi
if [ "$1" = "Spotify" ]; then
./sony Home &
sleep 1.8
./sony Down &
sleep 0.2
./sony Down &
sleep 0.2
./sony Down &
sleep 0.2
./sony OK &
echo "COMMAND: $1"
exit 1
fi
if [ "$1" = "SpotifyFromSleep" ]; then
./sony PowerOn &
sleep 5
./sony Tv &
sleep 1.8
./sony Home &
sleep 1.8
./sony Down &
sleep 0.2
./sony Down &
sleep 0.2
./sony Down &
sleep 0.2
./sony OK &
echo "COMMAND: $1"
exit 1
fi
declare -A commandmap
commandmap[PowerOff]="AAAAAQAAAAEAAAAvAw=="
commandmap[PowerOn]="AAAAAQAAAAEAAAAuAw=="
commandmap[Netflix]="AAAAAgAAABoAAAB8Aw=="
commandmap[Home]="AAAAAQAAAAEAAABgAw=="
commandmap[Tv]="AAAAAQAAAAEAAAAkAw=="
commandmap[Up]="AAAAAgAAAJcAAABPAw=="
commandmap[Down]="AAAAAQAAAAEAAAB1Aw=="
commandmap[Left]="AAAAAgAAAJcAAABNAw=="
commandmap[Right]="AAAAAgAAAJcAAABOAw=="
commandmap[OK]="AAAAAQAAAAEAAABlAw=="
commandmap[Back]="AAAAAgAAAJcAAAAjAw=="
IRCC=${commandmap[$1]}
if [ "$IRCC" = "" ]; then
echo "Unkown command $1"
exit 1
fi
code=$(curl -sw "%{http_code}" --silent -XPOST http://$SonyBraviaIP/sony/IRCC -H "X-Auth-PSK:$SonyBraviaPreSharedKey" -d "<?xml version=\"1.0\"?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:X_SendIRCC xmlns:u=\"urn:schemas-sony-com:service:IRCC:1\"><IRCCCode>"$IRCC"</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>" -H 'Content-Type: text/xml; charset=UTF-8' -H 'SOAPACTION: "urn:schemas-sony-com:service:IRCC:1#X_SendIRCC"' -o /dev/null)
if [ "$code" = "200" ]; then
echo "${commandmap[$1]} $1: ✓"
else
echo "${commandmap[$1]} $1: Command failed (HTTP_CODE: $code, try running it in a console)"
exit 1
fi
Script plaatsen in de map
/home/pi/domoticz/scripts/
Executable maken
Aanroepen in bovenstaande map, PowerOn is de $1 in de bash script
./filename PowerOn [enter]
In Domoticz kun je het script via LUA aanroepen, naam 'script_device_SONY.lua' bij mij. Plaatsen in.
/home/pi/domoticz/scripts/lua
local TV_Devicename = 'TV 50W755C' --Devicename van je LUA switch
scriptPath = '/home/pi/domoticz/scripts/sony'
commandArray = {}
if (devicechanged[TV_Devicename] == 'On') then
cmd= scriptPath .. ' PowerOn &'
os.execute(cmd)
print('TV set PowerOn')
end
return commandArray
PC Windows 10- Start via WOL
- Shutdown via net rpc
Wake On Lan:
Wake on LAN eerst op je PC inrichten uiteraard. Test het eerst lokaal op je netwerk met een APP.
Ik begon met Etherwake maar volgens mij is wakonlan standaard op de PI al beschikbaar.
bash script, naam WOL in de map:
/home/pi/domoticz/scripts
executable maken
WOL bash script:
#!/bin/bash
#Variables
macPC="AA:BB:11:22:DD:EE" #fill in your device MAC
set -e
cd $(dirname $0)
if [ "$1" = "" ]; then
echo "Usage: $0 <COMMAND>"
exit 1
fi
if [ "$1" = "PC" ]; then
wakeonlan $macPC
echo "Send magic packet $1 $macNAS"
exit 1
fi
echo "WOL <COMMAND> UNKNOWN"
uitvoeren test via commandlin in de map
/home/pi/domoticz/scripts
command, PC is de $1 in de bash script:
lua script:
local PC_Devicename = 'PC' --Devicename van je LUA switch
scriptPathWOL = '/home/pi/domoticz/scripts/WOL'
commandArray = {}
if (devicechanged[PC_Devicename] == 'On') then
cmd= scriptPathWOL .. ' PC &'
os.execute(cmd)
print('WOL PC set ON')
end
return commandArray
Remote shutdown via net rpc
net rcp Domoticz Forum
Op je windows PC (Windows 10) bij mij. Heb je een gebruiker met wachtwoord.
Tevens doe het volgende:
In windows edit registry met regedit, toevoegen als deze niet bestaat.
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system]
"LocalAccountTokenFilterPolicy"=dword:00000001
Execute CMD met admin rechten (rechtermuis op CMD en open as administrator.
sc config RemoteRegistry start= auto
sc start RemoteRegistry
Reboot je PC.
Op je Raspi:
sudo apt-get install samba-common
sudo apt-get install samba-common-bin
Plaats een remote_shutdown script in
/home/pi/domoticz/scripts
#!/bin/bash
#variables
IPPC =192.168.1.110 #IP adress PC
UsernamePC=username #Username PC
PasswordPC=password #Password PC
set -e
cd $(dirname $0)
if [ "$1" = "" ]; then
echo "Remote Shutdown : $0 <COMMAND>"
exit 1
fi
if [ "$1" = "PC" ]; then
sudo net rpc -S $IPPC -U $UsernamePC%$PasswordPC shutdown -t 1 -f
echo "Remote Shutdown : $0 $1"
exit 1
fi
echo "Remote Shutdown <COMMAND> UNKNOWN"
Maak hem executable
Test het script op je PI in de map:
/home/pi/domoticz/scripts/
commando, $1 is hier PC.
./remote_shutdown PC[enter]
Maak een switch aan en een lua file:
/home/pi/domoticz/scripts/lua/
local PC_Devicename = 'PC' --Devicename van je LUA switch
scriptPathShutdown = '/home/pi/domoticz/scripts/remote_shutdown'
commandArray = {}
if (devicechanged[PC_Devicename] == 'Off') then
cmd= scriptPathShutdown .. ' PC &'
os.execute(cmd)
print('Remote shutdown PC')
end
return commandArray
Et voila uw pc wordt afgesloten
NAS Thecus N52000XXX- Start via WOL
- Shutdown via SSH
Wake On Lan
Wake on LAN eerst op je NAS inrichten uiteraard. Test het eerst lokaal op je netwerk met een APP.
Zelfde als WOL van de PC, met als toevoeging op de bash file
macNAS="AA:BB:11:22:DD:EE" #fill in your device MAC
if [ "$1" = "NAS" ]; then
wakeonlan $macNAS
echo "Send magic packet $1 $macNAS"
exit 1
fi
en lua file een entry aanmaken voor je NAS switch, zie WOL bij de PC
Shutdown via SSH
Onderstaand gaat deels specifiek over de Thecus N5200xxx NAS. Maar het SSH remote inlog en een shutdown commando geven kan ook voor andere doeleinden geschikt zijn waar SSH gewenst is.
Met bash via ssh zonder password (met een .pub key in authorized_keys gekopieerd) een shutdown commando geven.
Installeer de SSH module HiSSH,, via auto module installation
Installeer
META, dit om een copy script te starten na startup
De NAS zal authorized_keys bij herstart in de map /root/.ssh op je nas overschrijven. Geen idee waarom en ik kon het niet vinden om dit uit te zetten.Je kunt ook /etc/ssh/sshd_config het pad naar authorized_keys wijzigen naar een map waar je key in staat maar bij mij was /etc/ssh/ filesystem write protected
Zet SSH_copy in /raid/data/module/META/system/etc/startup (zorg ervoor dat je deze aanpast zodat hij de nieuwe authorized_keys file goed kopieert)
code:
1
2
3
4
5
6
7
8
9
10
| #!/bin/bash
set -e
fromDIR = /raid0/data/Frank/SSH/pub_sync/authorized_keys #dir where the original authorized_keys file is locatie
toDIR = /root/.ssh/authorized_keys #dir where the original authorized_keys file nees to be copied to
cd $(dirname $0)
cp $fromDIR $toDIR
echo "Copy SSH authorized_keys to /root/.ssh/ " |
ssh naar je NAS:
voer je password in
ga naar
en open de authorized_keys file, Meer info over VI
hier
delete de eerste line dmv dd (geen idee wat die eerste key is, ik heb hem verwijderen)
sla op en sluit vi af ESC :wq!
Exit je SSH op je NAS
Nieuwe SSH inlog op je Raspberry pi
un: pi
pw: raspberry
maak een rsa.pub key aan voor PI
ssh-keygen -t rsa
ENTER
ENTER
ENTER
in de map
vi id_rsa.pub
hier zie je je key die je aangemaakt hebt (id_rsa.pub)
ga uit je VI, ESC :Q!
ssh copy deze naar je nas zodat je zonder password je nas kunt bereiken
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.100
vul je password in van je NAS
un: root
pw: eigen password van je web interface van je NAS
Als het goed is krijg je een melding dat er 1 key is gekopieerd.
ssh naar je nas via je PI
als het goed is hoef je nu geen password in te voeren. Dan is je SSH key goed gekopieerd in de authorized_keys op je NAS.
exit SSH naar je NAS
Daarna op je PI
SU en vul je root pass in
geen password bekend?
sudo passwd root
pw root (2x) (of kies iets anders)
en log dan in met SU
Ga naar
maak een rsa.pub key aan voor root
ssh-keygen -t rsa
ENTER
ENTER
ENTER
in de map
vi id_rsa.pub
hier zie je je key die je aangemaakt hebt (id_rsa.pub)
ga uit je VI, ESC :Q
ssh copy deze naar je nas zodat je zonder password je nas kunt bereiken
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.100
vul je password in van je NAS
un: root
pw: eigen password van je web interface van je NAS
ssh naar je nas via je SSH op je PI terwijl je SU bent
als het goed is hoef je nu geen password in te voeren. Dan is je SSH key goed gekopieerd in de authorized_keys op je NAS.
ga op je NAS naar de map
Hier staat de fle authorized_keys in
vi authorized_keys
Je ziet nu als het goed is 2 entries met ssh-rsa beginnend (oor de user pi en root)
quit VI, ESC :Q!
kopieer dit bestand naar een plek op je NAS, dit is dus het juiste bestand wat bij een reboot terug gezet moet worden op deze plek dmv SSH_copy van META.
exit SSH naar je NAS
exit SU op je PI
controleer of de SSH_copy werkt:
Ga naar
/raid/data/module/META/system/etc/startup/
En voer uit
als het gelukt is zie je de echo " Copy SSH authorized_keys to /root/.ssh/ "
nas shutdwon command
Link met info over Thecus shutdown
Log in op je NAS
maak een dir aan:
mkdir -m 0755 /raid/data/_tools_
Maak een schript shutdown aan in deze map.
Script:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| #!/bin/sh
cd /
cmd="/bin/false"
if [ -x /img/bin/sys_halt ] ; then # 64bit
echo "64 Bit shutdown"
cmd="/img/bin/sys_halt"
elif [ -x /img/bin/model/sysdown.sh ] ; then # 32bit v2.1+
echo "32 Bit 2.1+ shutdown"
cmd="/img/bin/model/sysdown.sh poweroff"
elif [ -x /img/bin/sysdown.sh ] ; then # 32bit < v2.1
echo "32 bit <2.1 shutdown"
cmd="/img/bin/sysdown.sh poweroff"
else
echo "No shutdown script found!"
cmd="/bin/false"
fi
trap "" 1 2 3 13 15
exec ${cmd} </dev/null >/dev/null 2>&1 & |
maak de script executable
chmod 0755 /raid/data/_tools_/shutdown.sh
probeer het script :
als het goed is zie je wat echo in je commandline en gaat je NAS nu uit
start je nas op
ssh naar je PI:
un: pi
pw: raspberry
is je NAS helemaal opgestart? controleer of je op je NAS kunt inloggen zonder password:
ssh root@192.168.1.100
als het goed is heeft META de file geschreven in /root/.ssh/authorized_keys
vi /root/.ssh/authorized_keys
en controleer de inhoudt met je oorspronkelijke bestand
exit VI: :Q!
exit SSH op je NAS
nu zit je nog in je raspberry, als je SSH zonder password kon opzetten naar je NAS run het shutdown commando vanaf je raspberry:
ssh root@192.168.1.100 /raid/data/_tools_/shutdown.sh
gaat je NAS uit? Good job commander
Voor domoticz:
bash file remote_shutdown plaatsen in
/home/pi/domoticz/scripts
Executable maken:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| #!/bin/bash
set -e
cd $(dirname $0)
if [ "$1" = "" ]; then
echo "Remote Shutdown : $0 <COMMAND>"
exit 1
fi
if [ "$1" = "NAS" ]; then
ssh root@192.168.1.100 /raid/data/_tools_/shutdown.sh
echo "Remote Shutdown : $0 $1"
exit 1
fi
echo "Remote Shutdown <COMMAND> UNKNOWN" |
via een device.lua en een switch kun je het script aanroepen bij het OFF commando.
code:
1
2
3
4
5
6
7
8
9
10
11
12
| local WOL_Devicename_NAS = 'NAS N5200XXX'
local WOL_Setname_NAS = 'NAS'
scriptPathShutdown = '/home/pi/domoticz/scripts/remote_shutdown'
commandArray = {}
if devicechanged[WOL_Devicename_NAS] == 'Off'then
print (devicechanged[WOL_Devicename_NAS])
cmd= scriptPathShutdown .. " " .. WOL_Setname_NAS .." $"
print (cmd)
os.execute(cmd)
end
return commandArray |
LET EROP DAT JE JE ssh-copy-id onder SU /root/.ssh/ ook hebt gedaan!!! Anders kan domoticz/raspi geen SSH zonder pw opzetten.
Tadaa als het goed is werkt het? Off op de schakelaar zet de NAS op uit
[
Voor 47% gewijzigd door
Falcon Heavy op 16-07-2016 11:10
]