CHANGE/ADD attribute from person

Hello,

i try to add/change an attribute to my person.ben
i try already different ways to add “last_room” attribute to my person.

customize.yaml:

customize:
  person.ben:
    last_room: "None"

this works, but when i change the attribute “last_room” with Automation:

action: python_script.exec
metadata: {}
data:
  file: python_scripts/set_state.py
data_template:
  entity_id: person.ben
  last_room: "{{ states('sensor.ben_iphone_ble_area') }}"

The new area “last_room” get changed but after some secounds it changed back to “None”.

In the next step i try to build an automation when “last_room” is “None” then run set_state.py

{% set test = state_attr('person.ben', 'last_room')|list|join(' ') %}
{{test}}
{% if test == 'N o n e' %}
true
{% else %}
false
{% endif%}

How i can remove the spaces? And is there any easier way to do this all?

My head is spinning after hours of trying it :slight_smile:

If HA does not want you to change the attribute then perhaps that is not how you should do it.
Forcing it with an automation that probably will trigger very frequent is probably not a good idea.

I realize you want the attribute there on the person entity but for what reason?
Why can’t this just be a sensor by itself? Are you going to add the person entity on a dashboard somehow and display both location and room at the same time some how?

@Hellis81
yes i want this attribute enity for my dashboard :slight_smile:
and i want to lean how this works in jinja :slight_smile:

Just remove the list and join then.

{% set test = state_attr('person.ben', 'last_room') %}
{% if test == 'None' %}
true
{% else %}
false
{% endif%}

Or simply:

{{state_attr('person.ben', 'last_room') == "None" }}
1 Like

@Hellis81 thank you

you know maybe why this isn’t working:

customize.yaml:

customize:
  person.ben:
    last_room: "{{ states('sensor.ben_iphone_ble_area') }}"

i just see the code as value

Probably because you can’t template in customize.

There seems to be a lot of clues that this is not the way to do it.

ok, i got it working.

automation:

alias: Testyyyy
description: ""
trigger:
  - platform: homeassistant
    event: start
  - platform: template
    value_template: |-
      {% set test = state_attr('person.ben', 'last_room') %}
      {% if test == 'None' %}
      true
      {% else %}
      false
      {% endif%}
condition: []
action:
  - action: python_script.exec
    metadata: {}
    data:
      file: python_scripts/set_state.py
    data_template:
      entity_id: person.ben
      last_room: "{{ states('sensor.ben_iphone_ble_area') }}"
mode: single

I there a code to catch all persons and/or areas/rooms?