Hi all,
After a lot of research I have figured out a way to use the slide function on the wallmote. I found a python script (based on https://gist.github.com/clintoncrick/f7aeb59bd314f6cb6b3fd0d103e23ddc) and modified it to detect the slide function.
Configuration
To detect the slide function parameter 4 Report Type of the wallmote must be set to Send Central Scene Command Notification and Configuration report. Once set, two extra parameters will appear: Parameter #9 and Parameter #10 when you swipe up/down on one of the buttons.
Create the following input_number:
light_step:
name: 'Step the lights this much'
initial: 20
min: 1
max: 64
step: 1
#######################################################################
light_minimum:
name: 'No dimmer than this'
initial: 5
min: 1
max: 255
step: 1
#######################################################################
light_maximum:
name: 'No brighter than this'
initial: 255
min: 50
max: 255
step: 1
Python script
Use the following code to extract openzwave logfile and monitor the slide functon, replace OZW_Log file path with your HA installation, the wallmote location and light entities according to your enrivironment:
edited: 10-jan-2019:
I have tidied up the script further and got rid of redundant codes
#!/usr/bin/env python3
Import socket
import requests
from subprocess import Popen, PIPE
import json
##Match Rule
##Match the start of swipe
MATCHER1 = 'Received Configuration report: Parameter=9'
##Match the end of swipe
MATCHER2 = 'Received Configuration report: Parameter=10'
##Match which button is used on the wallmote quad
MATCHER3 = 'Decrypted Packet: 0x00, 0x70, 0x06, 0x09, 0x04'
def extract_value(line):
value = line.split('=')[-1].strip()
return int(value)
# variable
event = 'script.dimmer'
##HA information
URI = 'http://192.x.x.x:8123/api/services/script/turn_on'
TOKEN = 'secret'
#TOKEN = False
OZW_LOG = 'YOUR OZW_Log.txt FILE PATH'
debug = True
##Open the tail of our OZW_Log and scan for new lines;
log = Popen(('/usr/bin/tail', '-F', '-n', '0', OZW_LOG), stdout=PIPE)
while True:
##Get most recent line and massage it;
line = log.stdout.readline()
if not line:
break
line = line.strip().decode('utf-8')
##Fast match
if MATCHER1 not in line:
if MATCHER2 not in line:
if MATCHER3 not in line:
continue
if "Parameter=9" in line:
nodeID = line.split(',')[1].strip().lower()
if "node002" in nodeID:
node = "WALLMOTE LOCATION (eg. bedroom, living room)"
if "node003" in nodeID:
node = "OTHER WALLMOTE LOCATION (eg. game room)"
value9 = extract_value(line)
continue
elif "Parameter=10" in line:
value10 = extract_value(line)
elif "Decrypted Packet:" in line:
button = line.split(',')[-4].replace(' 0x0','').strip()
continue
if value9 < value10:
action = 'swipe_up'
else:
action = 'swipe_down'
if node is not None:
if "LOCATION WALLMOTE 1" in node:
if "1" in button:
light_id = "LIGHT ENTITY_ID"
if "2" in button:
light_id = "LIGHT ENTITY_ID"
if "3" in button:
light_id = "LIGHT ENTITY_ID"
if "4" in button:
light_id = "LIGHT ENTITY_ID"
elif "LOCATION WALLMOTE 2" in node:
if "1" in button:
light_id = 'LIGHT ENTITY_ID'
if debug:
print(URI)
if debug:
print(event)
if event:
data = {"entity_id": "{0}".format(event), "variables":{"light_id": light_id, "swipe_action": action}}
if debug:
print(data)
if TOKEN:
resp = requests.post(URI, data=json.dumps(data), headers={'Authorization': 'Bearer {0}'.format(TOKEN), 'content-type': 'application/json'})
else:
resp = requests.post(URI, data=json.dumps(data), headers={'content-type': 'application/json'})
if debug:
print(resp)
Make sure to generate a Long-Lived Access Tokens in HA and replace ‘secret’ in the script with the generated token.
This script must be running at all times to read the OZW log file (background).
HA script
Use the following code to control the slide up/down functon (dim up/down)
Edited: 10-jan-2019:
I have consolidated 2 scripts (swipe up and swipe down) into one
edited: 12-jan-2019:
Solved a bug that light will be turned off (brightness = 0) when brightness reached its lowest. Now brightness will be set to 5 when its value falls below it.
Dimmer:
dimmer:
sequence:
- service: light.turn_on
data_template:
entity_id: '{{ light_id }}'
brightness: >-
{% set domain, name = light_id.split('.') %}
{% set current = states[domain][name].attributes.brightness | int %}
{% set step = states('input_number.light_step') | int %}
{% set action = swipe_action %}
{% if action == 'swipe_up' %}
{% set next = current + step | int %}
{% elif action == 'swipe_down' %}
{% set next = current - step | int %}
{% endif %}
{% if next > states('input_number.light_maximum') | int %}
{% set next = states('input_number.light_maximum') | int %}
{% elif next < states('input_number.light_minimum') | int %}
{% set next = states('input_number.light_minimum') | int %}
{% endif %}
{{ next }}
This will only work for non z-wave lights. And the dimming is very responsive. I run the scripts on a Pi and it works beautifully. Currently on HA 0.84.6.
The codes I provided here are the courtesy of others in this forum. I would like to thank @petro for his inspiration https://community.home-assistant.io/t/help-with-data-template-using-dynamic-entity-names/50587/20:
or if you want to pull it out of the state machine directly
```
{% set domain, name = entity_id.split('.') %}
{% set current = states[domain][name].attributes.color_temp | int %}
I hope this works for those who want to use the slide function. I am open to any improvement and suggestion to make this ‘workaround’ better and more efficient!
UPDATE 15 Jan 2021 - migrated to openzwave
I just migrated to the new openzwave and now there is no need to run this script in the background. The new solution makes use of the script provided by @phhe here. Thanks to his code there is no need to run the script continuously. The new solution is in this post.