custom-components / pyscript

Pyscript adds rich Python scripting to HASS
Apache License 2.0
894 stars 47 forks source link

Feature Request: exclude from recorder #577

Open leo-b opened 10 months ago

leo-b commented 10 months ago

Hi!

I am using pyscript for an equivalent of 'state based template entities'.

state.persist('pyscript.sensor_mydouble')

# "template sensor that doubles the original value"
@state_trigger('sensor.mysensor')
def mydouble_on_value_change():
    pyscript.sensor_mydouble = 2 * sensor.mysensor

I also need to take some temporary attributes from the original entity that are only used for calculations:

@state_trigger('sensor.mysensor.data')
def mydouble_on_attr_change():
    # attribute data contains only auxiliary data
    # that souldn't be recorded
    try:
        data = [ d.copy() for d in sensor.mysensor.data ]
        for elem in data:
            elem['price'] *= 2
    except Exception as e:
        data = None
    pyscript.sensor_mydouble.data = data

Those attributes shouldn't be archived in recorder history: https://developers.home-assistant.io/docs/core/entity/#excluding-state-attributes-from-recorder-history

It would be nice if pyscript would support that.

Cheers, --leo