Get Sonoff IPaddress

I wanted a way to get the IP address of my tasmota Sonoff

just need a hand to automate it

I have

  - platform: mqtt
    name: "SonOff IP"
    state_topic: 'stat/Wemos_fan/RESULT'
    value_template: "{{ value_json.IPAddress1.split(' ')[1].replace('(','').replace(')','') }}"

if i send this mqtt topic

cmnd/Wemos_fan/ipaddress

with a payload of 1 ( think it can be anything )
and I get this back

image

Happy Camper
This got me Thinking why can’t i have a input_select with all my sonoff in it so

sonoff_list:
    name: SonOff List
    options:
      - SONOFF5
      - SONOFF6
      - SONOFF7
      - SONOFF10
      - SONOFF11
      - workshop
      - Wemos_fan
    initial: Wemos_fan

So why question is

How do I change the state_topic in the SonOff IP to match the SonOff List I have selected

and the samw with mqtt.publish

I played in the Templates and work out this

stat/{{ states("input_select.sonoff_list") }}/RESULT

and

cmnd/{{ states("input_select.sonoff_list") }}/ipaddress

don’t know how to add it to the state_topic and mqtt.publish

then the outcome would look like this

image

Thanks

I don’t believe you can template in the command or state topics, only the payload.

thanks starting think down that track only because U have to restart when you add something.

Bugger does that mean i have to lean python.

What is it that you’re trying to achieve ? Is it matching the IP to the name ?

just want the IP address just in case I have to edit it

I do this by reserving addresses in my router.
I also have a ‘links’ page in Home Assistant with links to the address of all my IOT devices.
I then just need to click on the link to open the config / login page page of whatever device I want to change.

1 Like

my understanding is
can only do it if you know mac address but frist you need the IP address then you can get the mac address then get the router to give it a Ip address

question how do you maintain the link or are they all static address.

1 Like

I have got mark 1 working

and it doing what I want it to do

As i flash all my ESP8266 and ESP32 with “tasmota” everything is setup in the user_config.h which will join my network. when the ESP8266 reboot after flashing join the network with a IP address then I have to go into router or use fing to find the IP address but thinking out side the Square .
I have given it a project name “SONOFF-TMP” which is part of the Mqtt topic
then I run this script

get_gonoff_ip:
  alias: Get Sonoff New IP (SONOFF-TMP)
  sequence:
  - data:
      topic: cmnd/SONOFF-TMP/ipaddress
    service: mqtt.publish

it returns

12:49:17 MQT: stat/SONOFF-TMP/RESULT = {“IPAddress1”:“0.0.0.0 (192.168.1.103)”}

I then use the this sensor

  - platform: mqtt
    name: "New SonOff IP"
    state_topic: 'stat/SONOFF-TMP/RESULT'
    value_template: "{{ value_json.IPAddress1.split(' ')[1].replace('(','').replace(')','') }}"    

to show me its IP address
image
then I finishing off configuring the module setting the switchmodes add bits to it.
The Last thing to change is the Mqtt Topic and reboot it add it to HA Its Done

I really like what you did here. I was just farting around this morning. I’m running Tasmota on most of my nodes and I try to assign them in the router but moving stuff around becomes confusing.

I had this value template idea this morning:

{{ test_json.IPAddress1[9:-1] }}

Much less sophisticated than yours and this issues the response to the IPAddress command. I’m going to try to implement what you’ve done above.

Very helpful and I think a more common problem than people let on.

UPDATE:
I let my sonoffs OTA update from the server so I don’t get the benefit of static IP at compile time. I think it’s a reasonable tradeoff. What I typically do is issue a STATUS5 Command to the “sonoffs” group and all the units count off their netdata. The netdata looks like this:

COMMAND:

/cmnd/sonoffs/Status 5

RESPONSE

stat/huzzah/STATUS5 {"StatusNET":{"Hostname":"huzzah-5336","IPAddress":"10.10.xxx.xxx","Gateway":"10.10.xxx.xxx","Subnetmask":"255.255.255.0","DNSServer":"10.10.xxx.xxx","Mac":"xx:xx...","Webserver":2,"WifiConfig":3}}

Then I use the value template on an MQTT Sensor

  - platform: mqtt
    name: "Huzzah NetData"
    state_topic: "stat/huzzah/STATUS5"
    value_template: "Hostname:{{ value_json.StatusNET.Hostname }}, IP:{{ value_json.StatusNET.IPAddress }}, MAC:{{ value_json.StatusNET.Mac }}"

Which Yields:

sensor.huzzah_netdata	Hostname:huzzah-5336, IP:10.10.xxx.xxx, MAC:xx:xx...

And in the frontend:
Capture

So now I just need to issue the shell command to the sonoffs group and theyll report in. Otherwise the status will just show as unkown, which is fine since I don’t need the overhead if I’m not changing things.

EDIT: I just reread above and I like your publishing to MQTT as a service. I wish I had seen that but was focused on the template so went with a shell command since I had that implemented under a command line alias.

2 Likes

Okay,

I ran with it a little bit. And I broke the cardinal DRY mantra but this is what I came up with before and after. It didn’t take long at all.

Like how I used the status 5 option didn’t think of using that one will have a play when I get home.

I have been playing with sonweb that is alsum

Thanks for the tip on SonWeb. Before I get lost down that rabbit hole, what do you use it for principally? Pretty awesome work. Does it offer much over MQTT commands?

It just put all your tasmota stuff in one place u can jump into each one and break then no fix them

I giggle when I see people hiding their LAN IP addresses. :smiley:

4 Likes

I know. It is not useful info, but every little clue to someone’s infrastructure helps someone infiltrate. Especially if a flaw in wifi pops up and you know the device running on a network is vulnerable.

Every time I do it I question whether it’s worth the effort.

Uh. Your private LAN is unroutable. There are absolutely zero ways that me knowing your private subnet will assist in me hacking into your network.

I would have to be sitting next to your house to see your wifi. And if I have your WiFi, I’m already in your lan. Knowing the private subnet prior to that wouldn’t gain me ANYTHING.

100% useless.

:wink:

1 Like

When I read your first comment, it struck me as odd that someone would come into a thread and not contribute at all to the topic at hand but post a snarky comment. I chose to try to de-escalate by admitting that it could be silly, which you seem to have taken as a challenge.

I have found the HA forums to be a helpful friendly environment that is usually free of trolling. By trolling, I use this definition.

People typically work through their problems together, often coming up with multiple creative solutions to the same problem, but the discussions are usually focused on the problem, not on an inconsequential unrelated issue. This thread is an example of that collaborative problem solving (using STATUS 5 or publishing a message using mqtt service).

I’m sure you have a lot of knowledge to contribute to the community and welcome your contributions to solving issues the community of users comes together to address. I wish you all the best.

It wasn’t a snarky comment. It was an observation. An observation that I find amusing, that I see all the time in various forums. That is all.

There was no challenge inferred. At all.

Your response indicated a lack of knowledge on the subject. I merely responded in kind with the knowledge I have on the subject. There was nothing trolling about it. When you are discussing a topic such as ‘Get Sonoff IP Address’, which by the way, is a vague topic name, and I merely opened it to read it thinking it was something actually network related…

This is where I got this morning. It works fine but I like your idea of using the input selection box because the page is an eyesore.

I say it works fine, but the way tasmota responds to commands is different from the routine TelePeriod status update. I say this because the Status 5 command works great but if you want to trigger a state response with
state
it comes back on the console with the topic
stat/sonoff/relay2/RESULT
which HA won’t parse with the value template because its not the routine Teleperiod issuance topic is
tele/sonoff/relay2/STATE

So my question is can you have an MQTT sensor read from two different topics?

Wildcards for the first part “stat” and “tele” and the last part “RESULT” and “STATE”