Update sensor attribute from automation

In case this is an X Y problem, what I’m trying to achieve is to update the status of a virtual device to show when the washing machine is running, stopped etc, based on a blueprint that monitors the power usage (Notify or do something when an appliance like a dishwasher or washing machine finishes)

I’ve set up a blueprint from the automation above but there was no way to show the status on the Dashboard. To get around this I created a sensor called “Washing machine status” with an attribute to update the state:

  - sensor:
      - name: "Washing Machine Status"
        unique_id: washing_machine_entity
        state: "{{ this.attributes.current_status | default('Unknown') }}"
        attributes:
          current_status: ""   

However I cannot find a way to update the current_status attribute from the automation. What’s the best way to approach this problem?

Here lies the problem with using blueprints…

Blueprints are use case specific and are fairly inflexible when you want them to “do something else” than what they were specifically designed to do.

in your case you are using a blueprint to create an automation to take actions (notify you of state) based on certain conditions (power usage, etc) specifically defined in the blueprint.

Since you want to add actions then you will need to modify the automation which means you are no longer using the blueprint.

You might as well just ditch the blueprint and create your own automation to do what you want it to do. You can still use the existing automation as a starting point to add to it.

BUT…

in this case I’m not sure you can use an automation to set a sensor attribute.

What I would do is create the sensor first and give it’s state based on the same power monitoring as was used in the automation to trigger the notification. Then use the sensor state in the automation to trigger the notification.

IOW, do it the other way around from what you are trying tgo do now.

you want = automation to trigger based on power, etc and set the sensor attribute

you should = set the sensor state based on power, etc and trigger the automation based on sensor state.

at least that’s MHO.

A sensor senses things, you can’t programmatically change it, any more than you can stop it raining or change the temperature in your house.

I went a slightly different route in the end. I set up a helper text input that is updated by calling the set text service. This helper is referenced in the sensor as putting the text on the dashboard shows an editable text entry.

  - sensor:
      - name: "Washing Machine Status"
        unique_id: washing_machine_entity
        state: "{{ states('input_text.washing_machine_status_text') | default('Unknown') }}"
1 Like