Hey,
I try to use an attribute of an entity, but the name of the attribute changes because it used a date/time as name.
With a ‘current state’ Node I get the wished attribute using JSONATA. But I need to switch the ‘2023-01-25 10:00:38’ into a variable (e.g. msg.lasttime) because I can get the equal time stamp somewhere else.
It is most likely possible, but we probably need some more info, like what is the actually source text like and what is the complete debug message from the current state node you use?
But the marked timestamp changes after the vacuum cleaner has cleaned.
I get this timestamp into e.g. msg.lasttime. But how can i paste that in the marked spot?
You appear to be trying to get a key value from an object, but where the key has to be a variable. JSONata should be able to solve this quite easily.
Assuming that msg.uhzeit going into the current-state node contains the time (key) of the cleaning cycle you are interested in
$lookup($entity().attributes, uhrzeit).completed
should return the Boolean value required. The function $lookup(object, key) takes the given entity attribute object and uses the value in uhrzeit as the lookup-key.
Alternatively, if you don’t have a variable with the key of interest, then it is possible to get the most recent key, without knowing what it is, and to check that.
I don’t have access to your data - you only provide a picture - so it is difficult to test fully. The second solution attempts to pick out the most recent attribute, and from this the ‘completed’ field. It does work for me under my testing, but will not work if there is no attribute value, or if the most recent attribute does not have ‘completed’ field set. In this case it would require a little more code to deal with that possibility.