Ok thanks I try.
111887xxxx is the serial number of the router. If I make the router/get wan request, it replies with the IP address 10.xx.xx.xx (it is a connection IP with 4G sim)
Router published it because I requested it from router/get wan. From Home Assistant, how do you make the request?
The path to the value you want is shown in the top right of the mqtt explorer window, although you have hidden part of it.
mqtt:
sensor:
- name: "Teltonika RUT Wan IP"
state_topic: "router/111887xxxx"
value_template: "{{ value_json['wan'] }}"
Not working, always “unavailable”
Logs then please.
What actually is the raw value of router/111887xxx ?
PS I assume you have added your mqtt broker integration on ha?
Mqtt integration is built in and working in Home Assistant (I have many devices using it).
I only know that, as per the screenshot posted by me, I ask the Router through Mqtt Explorer
router/get
wan
and the Router responds by publishing
router/111887****
wan=10.40.**.**
I’m sorry, but I didn’t understand the mechanism on Home Assistant to make this request. Is it enough to create the sensor?
So it is not a json response it seems
Creating the sensor will not make the request, it’ll only read the response. Now I’ve read your router docs, the MQTT Explorer screenshots are misleading. Try this:
mqtt:
sensor:
- name: "Teltonika RUT Wan IP"
unique_id: 5bc54f8b-7d41-4774-bfce-e98e92409d3e
state_topic: "router/111887???/wan"
switch:
- name: "Router WAN IP request"
unique_id: 2e49517c-f4b8-4836-9498-705c5950df6b
command_topic: "get/111887???/command"
payload_on: "wan"
payload_off: "wan"
Every time you toggle that switch (which you can do via an automation), the router should provide its IP to the sensor if configured as above. The unique_id
s are just random strings from the UUID generator, but you can use anything.
I am getting my head around mqtt explorer slowly. Using mosquitto_sub
is easier, but hey that’s another story.
What is published on router/111887xxxx/wan
if it has the ip address then your config should be
mqtt:
sensor:
- name: "Teltonika RUT Wan IP"
state_topic: "router/111887???/wan"
I tried, but it doesn’t work. The sensor always remains “unavailable” and I don’t understand why
I’ve just re-read the docs and edited my code. Switch command_topic
now starts get
not router
. Does that fix it?
The sensor will be unavailable
until the switch is toggled. I’d imagine MQTT Explorer is retaining values for display, but your sensor will only pick it up next time the router sends it to the broker, which it will only do when the request is made — which is by sending wan
to get/111887???/command
.
I tried to invoke the service from Developer Tools, and it works, I get the IP address in the sensor.
service: mqtt.publish
data:
topic: get/111887****/command
payload: wan
From the switch it doesn’t work though. I noticed that the switch remains pressed to on, and must be turned off manually.
In that case, forget the switch and call that service directly from an automation every few hours as you want.
I am trying to follow here, but am unable.
I have added to configuration.yaml
mqtt: !include mqtt.yaml
I have created the file mqtt.yaml with the contents:
sensor:
- name: SIP
state_topic: SIP/zones
availability:
- topic: SIP
payload_available: '"UP"'
payload_not_available: '"DOWN"'
value_template: "{{ value_json.zone_list }}"
The payload for the topic SIP/zones on the MQTT broker is:
{"zone_list": [0, 0, 0, 0, 0, 0, 0, 0], "zone_dict": {"Front": 0, "South": 0, "North": 0, "T1south": 0, "S05": 0, "S06": 0, "S07": 0, "S08": 0}, "master_on": 0}
When I create a card on my dashboard for the entity SIP I am shown
[0, 0, 0, 0, 0, 0, 0, 0]
This changes whenever the the payload changes.
If all entries are 0’s, I would notify a MySensors actuator with a 0. If an entry is 1 (only one entry can be non-zero), I would notify the MySensors actuator with the index of the non-zero. I have the MySensors notification working.
But I am at a loss at how to write an automation that reacts to these changes. When I start writing the automation, I come to a point where I need to select a “device”, but I have no “device”, I have an “entity”
Your help will be appreciated. I have already spent 6 hours determining that there is an indentation error in the documentation please let us avoid more experiences like that.
Hopefully you have fixed it?
The ‘device’ slot is a drop down. You can select other options.
Thank you for the reply. My steps are:
- (+ADD SCRIPT)
- Enter name of new script
- [+ ADD ACTION]
- click on Device (there is no entity, nor sensor to choose)
- click on ‘v’ of device drop down box
There is no entity to select, only “file editor”, “forecast”, “Home Assistant core”, etc.
You interact with entities via services, so click on call service, not device.
I think what I want is the State.
I change “”{{ value_json.zone_list }}"" to “{{ value_json }}” so the entire payload is accessible. I wrote this script:
alias: SetValvePerSIP
sequence:
- repeat:
count: "8"
sequence:
- if:
- condition: state
entity_id: sensor.sip
state: sensor.sip.zone_list[{{ repeat.index - 1 }}]
then:
- service: notify.mysensors
data:
target: Zone
message: "{{ repeat.index }}"
- service: switch.turn_on
data: {}
target:
entity_id: switch.start
mode: single
The then section sends the data to MySensors (which works)
It is the if that doesn’t seem to work.
First question is easy (?). Since the index starts with 1 and the array starts with zero, does the jinja code, as I have done here, select the right “zone”?
OK, the tough part: sensor.sip.zone_list[ index ] Is this the right syntax for getting the state of the particular value?
I’m really out of my depth here!