Put variable in path of mqtt sensor topic

Hi!

Guys, it possible to replace year in path of topic with a variable of current year?

    - name: 'money_total_january'
      state_topic: "bills/total/2024/01"

to something like this: state_topic: "bills/total/{{ now().year }}/01" - but this, is not working…

According to the documentation for MQTT Sensor, no.

The state_topic option expects a string (it would say template otherwise).

An MQTT topic supports wildcards but I don’t know if it’s suitable for your specific application.

bills/total/+/01
1 Like