How to combine attributes?

So I’ve been re-working my Zanzito GPS script (I’ve since learned more than I did when I first wrote it) and I’m running into a problem combining attributes, for example:

# triggered Entity
trigName = data.get('entity_id')
trigState = hass.states.get(trigName) # newState
trigAttr = trigState.attributes.copy() # newstateAttributes
trigStatus = trigState.state # newStatus

# metatracker Entity
metaName = "device_tracker." + data.get('meta_entity')
metaState = hass.states.get(metaName) # currentState
metaAttr = metaState.attributes.copy()
metaStatus = metaState.state

This works fine - the problem is when I’m trying to load my metaTracker with attributes from both:

hass.states.set(metaName, trigStatus, trigAttr)
hass.states.set(metaName, trigStatus, metaAttr)

I suspect there’s some clobbering going on here (which to some extent is fine if metaAttr clobbers values from trigAttr) but is there a better way to combine them into one set of attributes and then set the states?

Edit: example data. In my case, device_tracker.vals is an iCloud device_tracker and device_tracker.val is my metaTracker - I’d like to combine the values from both with the metatracker having priority with regards to gps coords. As you can see, source_type doesn’t merge in (for example.)


I think you can try:

trigAttr.update(metaAttr)

Then use trigAttr.

1 Like

Sweet. That was the ticket, much appreciated Sir!

Source_Type is still NULL though. I added an additional statement that if trigAttr == gps then update metaAattr accordingly. Don’t suppose you’d be willing to eyeball my script and improve it beyond my pedestrian skill? :slight_smile: I’m already using a couple of yours as daily drivers :stuck_out_tongue:

Sure. Post it here or feel free to PM me.

Much appreciated! PM sent