How to update State attributes using set_state.py

Hi all,

I know this has been done to death but I couldn’t find any information on my particular problemI have an automation that uses doods to recognise a car in the camera feed, it then activates the platerecogniser addon to identify my license plate this is setup as a template as binary sensor and opens the gate. This individually works ok but the problem is that once the plate recogniser service recognises a plate its state variables stay the same so I can never subsequently trigger it unless it gets a false read in the mean time. So I setup set_state.py and that works ok for doods as the overall state is set to a number so I can easily set that back to 0 after the event and all is well but the platerecogniser has state attributes if I set the state is has no effect on the state attributes (I believe it used to? but was raised as a bug and subsequently changed). Can you set state attributes? and if so please let me know what that would look like or if their is a better way of doing this.

plate recogniser state attributes:

last_detection: null
vehicles:
  - {}
orientation: []
watched_plates:
  plate123: false
  plate234: false
statistics:
  total_calls: 2500
  usage:
    year: 2023
    month: 10
    resets_on: '2023-10-18T12:26:52.116715Z'
    calls: 50
  calls_remaining: 2450
regions:
  - gb
  - ie
save_file_folder: /media
save_timestamped_file: true
always_save_latest_file: true
unit_of_measurement: plate
friendly_name: platerecognizer_local_file

My binary sensor template triggers on watched plates plate1234 changing to true but once that happens it wont trigger again unless it triggers without seeing one of the plates. I could do with resetting that attribute back to false…any ideas?

Thanks

Steve

This is in HACS / Automation
pmazz/ps_hassio_entities: Python script to handle state and attributes of existing sensors and entities (github.com)

1 Like

Thanks a lot vingerha that did it! after working out how to give it a list rightly or wrongly I came up with this if anyone else has similar problems:

service: python_script.hass_entities
data:
        action: set_state_attributes
        entity_id: image_processing.platerecognizer_local_file
        state: '0'
        attributes:
          - watched_plates: {plate123: false, plate234: false}
        log_enabled: True