Hey everyone,
I was lucky enough to be given two T Beam meshtastic nodes for Christmas and have been having a play.
I have managed to get them up and running with the App and talking to each other etc. Also managed to fit a switch to one and configure as a sensor to send an MQTT message into Mosquito on HA. So far so good.
I have then used a sensor to get the message like this:
sensor:
################################################################################
### T Beam Meshtastic gate sensor ##############################################
################################################################################
- name: "gate sensor"
unique_id: "gate_sensor_messages"
state_topic: "msh/ANZ/2/json/MY CHANNEL/MY DEVICE"
value_template: >-
{% if value_json.from == 3234014136 and 'text' in value_json.payload %}
{{ value_json.payload.text | trim }}
{% else %}
{{ this.state }}
{% endif %}
This gives me a state of ‘Gate triggered detected’ when I press the button.
So this is where I am stuck, I made an automation, Some I did my self and some of it is copied from different sources (with a little AI) but this is what I have:
- id: '1737355387967'
alias: Notify Gate Triggered with Reset
trigger:
- platform: mqtt
topic: msh/ANZ/2/json/MY CHANNEL/MY DEVICE
value_template: '{{ value_json.from == 3234014136 and value_json.payload.text is defined and value_json.payload.text.strip() == "Gate triggered detected" }}'
action:
- service: notify.alexa_media_family_echo_dot
data:
message: "We have visitors through the bottom gate, release the vicious sheep, hide the naughty chickens."
data:
type: announce
- delay:
seconds: 7
- service: mqtt.publish
data:
topic: msh/ANZ/2/json/The_Crumps/!c0c31914
payload: '{"from": 3234014136, "payload": {"text": "Gate closed"}}'
retain: false
This sort of works but seems to trigger on every MQTT message either to or from that device.
What am I missing?
Cheers
Hey Troon,
Thanks for you response and help.
HA is the last but one version but I have been using HA for a fair time and have some old automations from a long time ago, so I havent kept up with some of the new syntax I dare say… plus snippets from other places. Also jumped back and forth between automations.yaml in the files and the visual editor to get things working etc… So, I dont fully understand Jinja or JSON but try to get by and am not a programmer… I only use the AI for comparison or help on what something means etc I wouldnt fully use it.
I have had a read through the triggers info before, although a lot went over my head.
Then nothing else happens strangely, but I must be missing something? Did I have to add something to the line you provided in the value template?
From my understanding the template is saying if a payload of Gate triggered detected is received from device 3234014136 within the text part then continue with the automation, else do nothing.
If it wasn’t triggering why does the state change as it should… I just love to hate electronics…
Any ideas?
Here, the value_template in the trigger selects the contents of ['payload']['text'] using get() to protect against those keys not existing: that is then compared with the payload string “Gate triggered detected”.
If that trigger fires, the condition checks that the from key of the message was the correct number before proceeding.
If that still doesn’t work, have a look at some automation traces.
Hello,
Thanks for the advice, I tried to just trigger it off the sensor. That’s what I thought you could do, but it doesn’t work. If I say trigger on change from anything to Gate triggered detected it does nothing…
Will give your second suggestion a go later and report back…
Edit:
Nope using the GET and using the condition doesn’t work either.
I have looked at the traces part and it says there are no traces to see? I have never used these so may be doing something wrong…