Trigger-based template sensor and calling a shell command

So I have this scenario where I want to update a template sensor based on a couple of different data sources. I am not sure of the best approach and could use some advice.

When an event I’m interested in happens, I send a WebHook notification to HA, and build a Trigger-based Template Sensor to react to it and update some attributes based on the json data in that WebHook. So far so good.

But I also need to call a shell command when this Webhook Trigger occurs which will return some additional JSON data that I want to update some other attributes in the Template Sensor with at the same time.

As far as I can tell, I can’t call a Shell Command service from within my Jinja Template logic inside the state or attributes block?

Does anyone have a creative way to pull this off? Thanks!

Update: I figured it out! I somehow forgot that trigger template sensor definitions can have an action: block. Put the shell_command service call in there, and it runs when the trigger occurs and then I can use both the trigger.data and the shell_response[‘stdout’] data to populate the template sensor attributes. Super cool.

1 Like