Setting custom attribute to a device doesn't persist?

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’}

  1. nope. devices that get their values from a component will be overwritten from that component. so you set a custom attribute and the component rewrites it all back to original.
  2. i guess you now know why it isnt working. it can work with things like sensors you create in appdaemon or setting attribute states that are already there that wont be overwritten everytime (like group attributes)
  3. so yeah, it depends on how the component is set up and how the component does fill the values.

probably best to just read up on how to persist data locally within appdeamon in general (haven’t done this yet) and forget the idea of persisting to a device node then Rene?

i use sensors for a lot of things.
they get created the first time you set the state (so you dont have to do anything in HA) and keep the state and attributes as long as you dont restart HA.

but you can also use vars like “self.varname” and set them in the initialize.
then they will keep resistant as long as you dont restart appdaemon.

or you can create general vars (but for that i refer to the docs)