You’re correct. It just uses the service to call zwave.set_config_parameter
. Here is the code:
import appdaemon.appapi as appapi
#
# App to turn manage LED notification on GE Switch
#
# EXAMPLE appdaemon.yaml entry below
#
# LED Control:
# class: GE_switch_led_control
# module: GE_switch_led_control
# entities:
# - entity: fan.master_bedroom_fan_level
# parameter: '3'
# off_value: 'LED on when light on'
# on_value: 'LED on when light off'
# - entity: fan.living_room_fan_level
# parameter: '3'
# off_value: 'LED on when light on'
# on_value: 'LED on when light off'
#
#
# Arguments
#
# entity: the entity that is being monitored
# parameter: the zwave parameter that you would like to update
# off_value: the value to send when the device is 'off'
# on_value: the value to send when the device is 'on'
#
# Release Notes
#
# Version 1.0:
# Initial Version
#
#
# ####################################################################
# ####################################################################
class GE_switch_led_control(appapi.AppDaemon):
def initialize(self):
if "entities" in self.args:
for item in self.args["entities"]:
entity = item["entity"]
node_id = self.get_state(entity, "node_id")
parameter = item["parameter"]
off_value = item["off_value"]
on_value = item["on_value"]
msg = "{} setup for LED control using Node ID {}.".format(
self.friendly_name(entity), node_id)
self.log(msg, "INFO")
# initialize LED
# wait seconds
self.run_in(self.initialize_led(entity=entity, node_id=node_id, parameter=parameter,
off_value=off_value, on_value=on_value), 240)
# Setup Listener
self.listen_state(self.state_changed, entity=entity,
node_id=node_id, parameter=parameter,
off_value=off_value, on_value=on_value)
else:
msg = "GE Switch LED Control enabled but no entities configured."
self.log(msg, "INFO")
def state_changed(self, entity, attribute, old, new, kwargs):
node_id = kwargs["node_id"]
parameter = kwargs["parameter"]
off_value = kwargs["off_value"]
on_value = kwargs["on_value"]
if new == "on":
value = on_value
else:
value = off_value
msg = "{} is now {}, setting Zwave value to: {}.".format(
self.friendly_name(entity), new, value)
self.log(msg, "INFO")
self.call_service("zwave/set_config_parameter", node_id=node_id,
parameter=parameter, value=value)
def initialize_led(self, entity, node_id, parameter, off_value, on_value):
current_state = self.get_state(entity)
if current_state == "on":
value = on_value
else:
value = off_value
msg = "Zwave Ready - INITIALIZING: {} is now {}, setting Zwave value to: {}.".format(
self.friendly_name(entity), current_state, value)
self.log(msg, "INFO")
self.call_service("zwave/set_config_parameter", node_id=node_id,
parameter=parameter, value=value)
def log_notify(self, msg, level):
self.log(msg, level)
self.call_service("notify/notify", message=msg)
The initialization of the LED is throwing errors and I haven’t spent time to figure out what is causing it. But, that is only firing on App start.
Let me know if you have questions.