pmazz / ps_hassio_entities

Python script to handle state and attributes of existing sensors and entities
MIT License
58 stars 10 forks source link

set attribute for another entity id state #5

Closed ahmaddxb closed 3 years ago

ahmaddxb commented 3 years ago

How would i set the attribute of en entity from its state

YAML configuration



alias: Tasmota Firmware Update Notification
description: ''
trigger:
  - platform: time
    at: '15:34:00'
condition: []
action:
  - service: python_script.hass_entities
    data:
      action: set_attributes
      entity_id: sensor.tasmota_latest_version
      attributes:
        - latest_version: '{{(states.sensor.latest_tasmota)}}'
mode: single

**Screenshots**
If applicable, add your screenshots here.

**Version**
What is the version of the script?

**Additional information**
Add any other relevant additional information here.
pmazz commented 3 years ago

Hi, do you mean you would like to set the entity attribute to its state value ? If so, you need to adjust your code a little.

First, the rows entity_id: sensor.tasmota_latest_version and - latest_version: '{{(states.sensor.latest_tasmota)}}' should refer to the same sensor. tasmota_latest_version and latest_tasmota don't match, is this a typo ?

Second, the row - latest_version: '{{(states.sensor.latest_tasmota)}}' does not set the state value, but the whole state object (in json notation). You should change it to: - latest_version: '{{states.sensor.latest_tasmota.state}}' or even better: - latest_version: '{{states("sensor.latest_tasmota")}}'

Let me know if that helps.

ahmaddxb commented 3 years ago

yer that worked thanks, think is was a long day was trying to many things.