Can you use this.state in a macro call

I have a simple macro that I am testing

{% from 'consumption_filter.jinja' import filter %}
{{ filter(this.state) }}

This is the code in the template sensor

and this is the macro code

{% macro filter(prev_state) %}
    {{ prev_state }}
{% endmacro %}

It works if I pass a nubmer to it but if i pass this.state to it I get unavailable.

Am I using this wrong?

Sorry for some more clarification I want to use the current state of the template sensor and pass it to the macro. it seems like this.state does not work in the macro so I was hoping to pass it form the template to the macro every time I do I get the result unavailable

The variable “this” is not defined in the macro, so you cannot use it inside.
Why not using “this.state” as an input argument?

I was using it as an input to the macro but was getting weird results. I got it to finally work now

If you marked your post as a “solution”, then consider adding an explanation what was before, what was changed and how you got a positive result.

1 Like

I have no idea what the solution was as it just started working. I don’t know why or what I changed. I can post my code that works for others to see working examples. I marked it as answered so that people looking for unanswered issues would not bother with this one