I’m receiving an MQTT from my first tank using a Reef Angel controller. It provides multiple parameters all from an “out” channel. I’ve gotten it to flow in, but it shows T1, T2, T3, or PH whenever any of those values change. Ideally I get it to filter as they come in to the correct parameter for quick status and graphing. For example, PH flows is constantly, but temperatures (T1, T2, and T3) change less frequently. How do I make this into 4 states and send the appropriate value to that state?
Example feed:
PH:765
T2:681
PH:766
PH:765
PH:764
T1:702
T3:720
PH:765
So if going from top to bottom, I’d love 4 sensors here keeping stats with these end values and a graph available for PH:
Here is an idea that should get you started (I don’t know if this actually works).
It uses a template and in particular the split method to divide the message (based on :) into two halves, a key and value pair. It checks to see if the key is equal to the string “PH”, and if it does it will use its value (assumes the value is not a string), otherwise it will retain the same state it had before.
sensor:
- platform: mqtt
name: "Tank PH" #this should create a sensor named sensor.tank_ph
state_topic: "wolfpack/out"
value_template:>-
{% if value.split(':')[0] == "PH" %}
{{ value.split(':')[1] }}
{%- else -%}
{{ states("sensor.tank_ph") }}
{%- endif %}
If this works for “PH”, you can repeat this for “T1”, “T2”, and “T3”.