I’m trying to set some info in a device custom attribute however it doesn’t seem to persist? When I read from that device afterwards, or check in homeassistant states I don’t see it there. I used to do this in Vera (before it died) to save some persistent state relevant to the device.
Q1 - Is this possible? Should you able to persist a custom attribute?
Q2 - If yes, why doesn’t this code below work? Am I missing something?
Q3 - Is there a limitation in terms of the type of devices you can write custom attributes to to be persisted.
Code:
import appdaemon.appapi as appapi
class test(appapi.AppDaemon):
def initialize(self):
self.listen_state(self.test_callback, "input_boolean.test_switch", new = "on")
def test_callback(self, entity, attribute, old, new, kwargs):
state = self.get_state("zwave.switch_3", "all")
self.log("zwave.switch_3 BEFORE: %s" % state)
state_2 = self.set_state("zwave.switch_3", attributes = {"TestAttribute": "Testing_456"}) # <== ** HERE **
self.log("zwave.switch_3 AFTER: %s" % state_2)
Output
2018-03-18 11:04:13.053010 INFO test: zwave.switch_3 BEFORE: {‘state’: ‘ready’, ‘last_changed’: ‘2018-03-17T07:18:52.530333+00:00’, ‘entity_id’: ‘zwave.switch_3’, ‘attributes’: {‘max_baud_rate’: 40000, ‘sentCnt’: 140, ‘node_name’: ‘Switch 3’, ‘friendly_name’: ‘Switch 3’, ‘is_ready’: True, ‘manufacturer_name’: ‘Aeotec’, ‘receivedUnsolicited’: 1, ‘is_info_received’: True, ‘new_entity_id’: ‘zwave.switch_3’, ‘query_stage’: ‘Complete’, ‘averageResponseRTT’: 34, ‘receivedCnt’: 104, ‘retries’: 0, ‘lastRequestRTT’: 25, ‘is_awake’: True, ‘neighbors’: [1, 3], ‘receivedDups’: 1, ‘node_id’: 4, ‘is_failed’: False, ‘capabilities’: [‘listening’, ‘beaming’, ‘routing’], ‘product_name’: ‘DSC06106 Smart Energy Switch’, ‘receivedTS’: '2018-03-18 00:55:47:116 ', ‘old_entity_id’: ‘zwave.switch_3_4’, ‘is_zwave_plus’: False, ‘lastResponseRTT’: 35, ‘sentTS’: '2018-03-18 00:55:47:080 ', ‘averageRequestRTT’: 24, ‘sentFailed’: 0}, ‘last_updated’: ‘2018-03-18T00:55:47.321291+00:00’}
2018-03-18 11:04:13.149819 INFO test: zwave.switch_3 AFTER: {‘state’: ‘ready’, ‘last_changed’: ‘2018-03-17T07:18:52.530333+00:00’, ‘entity_id’: ‘zwave.switch_3’, ‘attributes’: {‘max_baud_rate’: 40000, ‘sentCnt’: 140, ‘node_name’: ‘Switch 3’, ‘friendly_name’: ‘Switch 3’, ‘is_ready’: True, ‘manufacturer_name’: ‘Aeotec’, ‘receivedUnsolicited’: 1, ‘is_info_received’: True, ‘new_entity_id’: ‘zwave.switch_3’, ‘query_stage’: ‘Complete’, ‘averageResponseRTT’: 34, ‘receivedCnt’: 104, ‘retries’: 0, ‘lastRequestRTT’: 25, ‘is_awake’: True, ‘neighbors’: [1, 3], ‘receivedDups’: 1, ‘node_id’: 4, ‘is_failed’: False, ‘capabilities’: [‘listening’, ‘beaming’, ‘routing’], ‘product_name’: ‘DSC06106 Smart Energy Switch’, ‘receivedTS’: '2018-03-18 00:55:47:116 ', 'TestAttribute’: ‘Testing_456’, ‘old_entity_id’: ‘zwave.switch_3_4’, ‘is_zwave_plus’: False, ‘lastResponseRTT’: 35, ‘sentTS’: '2018-03-18 00:55:47:080 ', ‘averageRequestRTT’: 24, ‘sentFailed’: 0}, ‘last_updated’: ‘2018-03-18T01:04:13.102086+00:00’}