#Referencing Template Code Between State and Attributes.

1 messages · Page 1 of 1 (latest)

somber island
#

I've built a template to process data from my local transit integration into a more useful sensor that I hope to use in an arrival board style lovelace card. There are four data points I'd like to have as the sensor state and attributes, but the template is ~50 lines long, so I want to avoid duplicating it for each attribute to keep my code clean. Is it possible to put a large block of code in the state template, then reference that code in the attributes? I've tried a few things without success: Making the state return a dict, and referencing individual attributes in the dict for the sensor attributes. Referencing variables directly. Referencing namespace variables etc.

somber island
#

Thanks for the tip! I've got it working though I'm not completely sure I did it in the "right" way. If I just use the stock import, it will return the same thing each time. So I added an extra "attribute" parameter so I can tell it which one I want it to return.