Vera z-wave energy monitors to HA

Hey folks,

Long story short I want to move my Home Assistant to a VM for easier management and backup. So I got a Vera hub to act as my z-wave and such interface. I’ve started to move a few things over to it such a switches and lights which work great. However my energy monitor data isn’t coming across. Any idea how to correct this? I have a few different flavors, all Aeon Labs. Can list out part number if needed. Any assistance would be greatly appreciated!

Thanks,
Dan

2 Likes

I’ve used a shell script with a REST call to the vera interface to extract sensor values. I ended up creating a cron job which runs frequently which extracts values into a file, and the sensors then access a shell script which reads the appropriate value from the file (assuming that makes sense!).

So my script called from CRON looks like:

#!/bin/bash
(
flock -x -w 10 200
wget -O /scripts/verastatus-cron.xml -o /scripts/verastatus-cron.log 'http://<ip>:3480/data_request?id=sdata&output_format=xml'
) 200>/var/lock/verastatuslock

sleep 30

(
flock -x -w 10 200
wget -O /scripts/verastatus-cron.xml -o /scripts/verastatus-cron.log 'http://<ip>:3480/data_request?id=sdata&output_format=xml'
) 200>/var/lock/verastatuslock

doubled up so that it runs twice in a minute from the cron job which runs every minute.

Then the sensor read script looks like:

(
flock -s -w 10 200

value=`xmllint --xpath "string(//devices/device[@id='$1']/@$2)" /scripts/verastatus-cron.xml`

if [ "$3" == "DATETIME" ]; then
   date -d @$value
else
   echo $value
fi

) 200>/var/lock/verastatuslock

which in HA is configured like this:

sensor 32:
- platform: command_line
  name: Sensor Battery
  command: '/bin/bash -c "/scripts/veraSensorValue.sh 109 batterylevel"'
  unit_of_measurement: "%"

where 109 is the device id, and batterylevel is the sensor attribute I’m extracting

another example in HA:

sensor 31:
- platform: command_line
  name: Room UV
  command: '/bin/bash -c "/scripts/veraSensorValue.sh 133 light"'
  unit_of_measurement: "Level"

Hope that makes sense and is useful for you :slight_smile:

2 Likes

@pembo yep make perfect sense, thanks! I’d love to test it out but my brand-new Vera Plus is dead and won’t boot. :frowning:

happened to my first one too… tried to recover it on myself and with their support team but in the end was given auth to return/get it replaced. The update process definitely screwed up my first one, which has made me very cautious about upgrading it subsequently :worried:

Mine was just chilling and it died. Went to bed and it was fine, woke up and it was dead. HOWEVER support did manage to bring it back to life! ~70 minutes remoted into my laptop connected direct to the unit and they were able to re-flash it and get it operational! Now to play with your scripts. :wink: Thanks!

@pembo so this is working great, thanks! However there seems to be an issue with multiple sensors. I have 5 energy monitors that need polled and it seems only the first one has constant updates. The others only update when HASS restarts. Any thoughts?

In additional any idea how to handle things like leak sensors? They show up as a switch in HASS.

the trick is not to rely on what the HA/pyvera pulls through.
I had some issues with it, which weren’t easy to get to the bottom of, so I went with REST integration to VERA.

The script should work fine for multiple sensors as the cron job should keep refreshing the xml from VERA that contains the sensor values (http://[ip]:3480/data_request?id=sdata&output_format=xml)

If you put that in a browser you can find any device and look for the value you want to pull out for a sensor. For a switch this is usually an attribute called status.

If its only refreshing on restart, it either implies the command line sensors aren’t refreshing in HA, or the cron job isn’t updating the file, so you could check the file on the box to make sure that this is updating outside of HA.

Only other thing to note in the scripts is the use of flock - just to avoid sensor reads during an update of the file from the cron job.

1 Like

I think I spoke too soon. It looks like some of the values only update when they change. It appears to be working correctly now for the few sensors I have in there.

A (maybe) final question. Are you using Alexa by chance? I can’t seem to get her to control z-wave stuff connected to the vera hub. I have the Hue emulation setup and she sees the switches but won’t control them for whatever reason.

It might be a config issue on my end, just thought I would check and see if you had gone down this path.

Really appreciate all your help!

Huh, so ONE of the 3 switches I have on the vera hub is controllable by Alexa through HA. The other two don’t do anything. Like after giving Alexa the command she just make the little timeout or whatever noise. She doesn’t respond with anything and nothing shows up in the app. Time to do a little more digging…

I’ve been using Alexa reasonably well with it. Bit of pain initially as I had the previous beta, and it ended up in right old mess, but the last update sorted it all out. You can use the link in the email to get back to the screen where you can name / include devices… had to do this a couple of times myself to add in some that were missing (which I’m sure I ticked originally!)

I think it’s just an oddity with names. Might need to tweak how they are presented. I was unable to get “Alexa: Norbert Off” to work however “Alexa: Norbert Light Off” seemed to work without issue. I don’t control most of the things with Alexa but wanted to at least make sure it was working. I THINK I’m getting closer to being able to migrate away from my Pi to a VM finally. I really do appreciate your help with this, I owe you a beer!

i’ve also got scripts to change scenes in vera as well as control switches/etc if you’re interested!?

Yes please!

Ok :slight_smile:


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"'
1 Like

This is sweet, thanks for sharing!

Hey @pembo

Are you pulling in voltage and current as well? I don’t see it in the XML dump. Not a hut issue, but I’ve had voltage issues in the past and like to keep an eye on it.

Thanks!

i’ve not got any devices that pull through voltage and current, but if they are in the vera ui, you should be able to find them in the xml…

They aren’t nor do I see them in the raw XML. I know the energy monitors supply this as I had it when connected directly to HASS. I’ll mess around and see if I can figure it out, thanks!

Rather late to this - but happy to help add more devices to the pyvera code so that are an effortless integration. If you raise an issue here https://github.com/pavoni/pyvera.

I think we already have energy monitoring for switches…

2 Likes

@gregd - The issue seems to be that from the Vera side it’s not picking up the voltage/current. I can’t find it in the GUI nor the raw XML.