Ok ![:slight_smile: :slight_smile:](https://community.home-assistant.io/images/emoji/twitter/slight_smile.png?v=9)
VERA Mode
Change Vera Mode (home/away/night/vacation)
Sets the mode of vera - change the houseModeParameter to whatever you need - I use this based on presence as it simplifies turning on/off devices in automations as this is then controlled via vera and I just set the right mode in the automation.
#!/bin/bash
#1=Home
#2=Away
#3=Night
#4=Vacation
wget -O /scripts/mode.xml -o /scripts/mode.txt "http://[IP]:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=SetHouseMode&Mode=1"
Get the vera mode value as a sensor
#!/bin/bash
value=`xmllint --xpath "string(/root/@mode)" /scripts/verastatus-cron.xml`
if [ "$value" == "1" ]; then
echo "Home"
fi
if [ "$value" == "2" ]; then
echo "Away"
fi
if [ "$value" == "3" ]; then
echo "Night"
fi
if [ "$value" == "4" ]; then
echo "Holiday"
fi
configuration.yaml
shell_command:
vera_home: '/bin/bash -c "/scripts/veraModeHome.sh"'
sensor 27:
- platform: command_line
name: House Mode
command: '/bin/bash -c "/scripts/veraModeValue.sh"'
Command line switches
veraSwitch.sh
#!/bin/bash
#Toggle a switch on or off in Vera
(
flock -x -w 10 200
#Call the rest service
wget -O /scripts/switch.xml -o /scripts/switch.txt "http://[IP]:3480/data_request?DeviceNum=$1&id=lu_action&output_format=xml&action=SetTarget&serviceId=urn%3Aupnp-org%3AserviceId%3ASwitchPower1&newTargetValue=$2"
#Echo the mode to the conf file
echo $2 > /scripts/conf/vera_device_$1
#Update the status xml file to reflect new value of switch
xmlstarlet ed --inplace -u "/root/devices/device[@id='$1']/@status" -v $2 /scripts/verastatus-cron.xml
) 200>/var/lock/lwrflockfile
veraDimmer.sh
#!/bin/bash
# Sets Dim level for a given device
# 1 = ID
# 2 = Dim Value 0 - 100
# 3 = Device (For tracing)
#wget -O /scripts/dimmer.xml -o /scripts/dimmer.log "http://[IP]:3480/data_request?id=action&output_format=xml&DeviceNum=$1&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=$2"
DIM=$(echo $2 | cut -d'.' -f 1)
if [ "$DIM" -gt "100" ]; then
exit
fi;
if [ "$DIM" -gt "1" ]; then
wget -O /scripts/dimmer.xml -o /scripts/dimmer.log "http://[IP]:3480/data_request?id=action&output_format=xml&DeviceNum=$1&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=$DIM"
echo 1 > /scripts/conf/vera_device_$1
xmlstarlet ed --inplace -u "/root/devices/device[@id='$1']/@level" -v $DIM /scripts/verastatus-cron.xml
xmlstarlet ed --inplace -u "/root/devices/device[@id='$1']/@status" -v 1 /scripts/verastatus-cron.xml
else
wget -O /scripts/switch.xml -o /scripts/switch.txt "http://[IP]:3480/data_request?DeviceNum=$1&id=lu_action&output_format=xml&action=SetTarget&serviceId=urn%3Aupnp-org%3AserviceId%3ASwitchPower1&newTargetValue=0"
xmlstarlet ed --inplace -u "/root/devices/device[@id='$1']/@level" -v 0 /scripts/verastatus-cron.xml
xmlstarlet ed --inplace -u "/root/devices/device[@id='$1']/@status" -v 0 /scripts/verastatus-cron.xml
echo 0 > /scripts/conf/vera_device_$1
fi;
veraSwitchStatus.sh
#!/bin/bash
#Gets the status of a switch from the cron xml
(
flock -s -w 10 200
status=`xmllint --xpath "string(//devices/device[@id='$1']/@status)" /scripts/verastatus-cron.xml`
if [ $status = 1 ]; then
echo 1 > /scripts/conf/vera_device_$1
exit 0
else
echo 0 > /scripts/conf/vera_device_$1
exit -1
fi
) 200>/var/lock/verastatuslock
configuration.yaml
switch:
platform: command_line
switches:
cmd_living_room_light:
command_on: '/bin/bash -c "/scripts/veraSwitch.sh 22 1 Lounge"'
command_off: '/bin/bash -c "/scripts/veraSwitch.sh 22 0 Lounge"'
command_state: '/bin/bash -c "/scripts/veraSwitchStatus.sh 22 Lounge"'
Dimmer uses a slider input
input_slider:
livingroom_brightness:
name: Brightness
min: 0
max: 100
step: 5
shell_command:
livingroom_slider: '/bin/bash -c "/scripts/veraDimmer.sh 22 {{states.input_slider.livingroom_brightness.state}} Lounge"'
and the automation from the slider change
- alias: Living Room Light - Adjust Brightness
initial_state: false
hide_entity: True
trigger:
platform: state
entity_id: input_slider.livingroom_brightness
action:
- service: homeassistant.turn_on
entity_id: switch.cmd_living_room_light
- service: shell_command.livingroom_slider
Vera Armable Devices
veraArmable.sh
#!/bin/bash
#Set an armable (security or sensor) device
(
flock -x -w 10 200
wget -O /scripts/arm.xml -o /scripts/arm.txt "http://[IP]:3480/data_request?id=lu_action&output_format=json&action=SetArmed&DeviceNum=$1&serviceId=urn%3Amicasaverde-com%3AserviceId%3ASecuritySensor1&newArmedValue=$2"
echo $2 > /scripts/conf/vera_device_$1
#Update the status xml file
xmlstarlet ed --inplace -u "/root/devices/device[@id='$1']/@armed" -v $2 /scripts/verastatus-cron.xml
) 200>/var/lock/lwrflockfile
Get an Armable Status
veraArmableStatus.sh
#!/bin/bash
#Get an armable status value
(
flock -s -w 10 200
status=`xmllint --xpath "string(//devices/device[@id='$1']/@armed)" /scripts/verastatus-cron.xml`
if [ $status = 1 ]; then
echo 1 > /scripts/conf/vera_device_$1
exit 0
else
echo 0 > /scripts/conf/vera_device_$1
exit -1
fi
) 200>/var/lock/verastatuslock
configuration.yaml
switch:
platform: command_line
switches:
cmd_living_room_sensor:
command_on: '/bin/bash -c "/scripts/veraArmable.sh 81 1 LoungeSensor"'
command_off: '/bin/bash -c "/scripts/veraArmable.sh 81 0 LoungeSensor"'
command_state: '/bin/bash -c "/scripts/veraArmableStatus.sh 81 LoungeSensor"'
VERA Harmony Plugin
Last one uses the harmony plugin to turn off all the devices it controls properly and is driven from an automation when everyone is out to make sure all devices turn off as defined in the harmony setup
veraHarmonyOff.sh
#!/bin/bash
wget -O /scripts/harmony.xml -o /scripts/harmony.txt "http://[IP]:3480/data_request?id=lu_action&output_format=json&DeviceNum=86&serviceId=urn:rboer-com:serviceId:Harmony1&action=StartActivity&newActivityID=-1"
configuration.yaml
shell_command:
lounge_tv_off: '/bin/bash -c "/scripts/veraHarmonyOff.sh"'