# Script to update an X10 dimmer module status in Domoticz when the level has been changed manually
#
# Adjust the value assigned to IDX to reflect the module idx number in Domoticz
# Adjust the value asssigned to ADDR to reflect the module house and device code
#
#!/bin/bash

IDX=2
ADDR=B3

# get the module's current dim level
LEVEL=`sudo -u pi heyu dimlevel $ADDR`

# debugging messages
# echo $LEVEL >> debug_dim.log & 
# curl "http://192.168.0.55:8099/json.htm?type=command&param=addlogmessage&message=Updating%20$ADDR%20to%20level%20$LEVEL"

# Update the Domoticz user variable holding the dim level. This MUST be done before updating the device to avoid action
curl "http://192.168.0.55:8099/json.htm?type=command&param=updateuservariable&vname=Bright_Level_$ADDR&vtype=0&vvalue=$LEVEL"

# This will update the slider (svalue) of the Domoticz device, but when the lua script is called, there will be
# no action, the calculated change in dim level, delta, will be 0.
curl "http://192.168.0.55:8099/json.htm?type=command&param=switchlight&idx=$IDX&switchcmd=Set%20Level&level=$LEVEL"


