Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Using pyscript functions instead of template sensors? #211

Unanswered
vvuk asked this question in Q&A
Discussion options

Howdy! Is it possible to use pyscript to build entirely new entities, similar to how template sensors/entities work? The built-in templating engine is... less than optimal. I believe I can already do almost all the needed bits with pyscript -- I can define triggers, and within that trigger function I can set state values. But I need a new synthetic entity to set state on; any suggestions on how I can create that?

You must be logged in to vote

Replies: 1 comment 3 replies

Comment options

I just saw #129 -- it looks like what I'm looking for. But is it required, or is there a less-elegant workaround possible before this is merged?

You must be logged in to vote
3 replies
Comment options

Okay, answering my own question. state.persist works perfectly well for this use case. Sample in case someone else comes looking for this:

POWER_ATTR = { "unit_of_measurement": "kW", "device_class": "power" }
state.persist('pyscript.tesla_card_grid_to_house', default_value="0", default_attributes=POWER_ATTR)
@state_trigger('sensor.powerwall_load_now', ...)
def recalc_power():
 ...
 pyscript.tesla_card_grid_to_house = 123.0
Comment options

so, I guess when you use auto_entities (hacs), you can automactly add this to lovelace (when you create the names in a smart way :) )

Comment options

You should mark this Discussion as "Answered".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /