How to only accept mqtt json value if other attribute correct

I’m having trouble trying to understand how to only use sensor mqtt messages that are of the correct type.

So I have topic/messages that look like:
emon/data {“type”:“power”, “pwr1”:688.0, …
emon/data {“type”:“totals”, “timp”:458782980, …

So for displaying the power I need to use only message where type == power and ignore the others.
Likewise for totals type and others.

I’m not sure that templating is quite the right place to filter the messages but I can’t even get that to work (probably because I don’t know how).

Any thoughts?

yes, templating is where it’s done.

{{ value_json.pwr1 if value_json.type == 'power' else 0 }}

Thanks. The syntax at least works. Problem is it doesn’t ignore where type != power it puts in zero (or blank if else clause is omitted). Is there a way to say “no change” as in else keep last value?

personally, i’d make separate topics for these devices instead of having a single topic for all devices. But if this is what you want then just get the state of itself.

{{ value_json.pwr1 if value_json.type == 'power' else states('') | float }}

Interesting. Thank you very much.

BTW regarding topics, yes I agree but that stuff has been running for 6yrs or more whereas HA barely 24hrs.