Let share with you my problem and the solution I’m trying to find with your help.
I have a Home Assistant system running in my main home with several lights, switches, locks, … connected both wifi and zigbee2mqtt.
I have another house with just an internet connection. In this 2nd house I would like to detect when a power outage occurs and when the power is recovered in order to go there if I need to save all the goods in the fridge.
My first idea is to use an esp8266 with ESPHOME plugged in any power socket in this second house and with some kind of “hearbeat” to be sent periodically to my local HA instance in my main house.
In this case, if the heartbeat comming from that 2nd house is not received during some time, it means that probably there is a power failure in that remote house and I can decide what to do (of course, it could also be fired because there is a problem with the WIFI or the internet in that 2nd house, but this is not so probably).
My question is if this concept is possible to be build up, and how to do it. I dont know if it is possible to send a “hearbeat” remotelly using ESPHOME to a HA instance with for example MQTT…
In esp module you can add wifi signal strength sensor and you’re already done. Ok, you can add, say, temperature/humidity sensor, too…
By default these sensors report state every 60 seconds (you can change that, though). If power goes out sensor (basically whole esp module) will become unavailable and you can create automation based on that. And, there’s no need for MQTT, esphome has direct connection to HA, you just add “esphome” integration.
I have wifi strenght and uptime sensors in every module in my network.
If you have a MQTT broker exposed in the Internet that can be one choice
Two other optiions could be ether to make use of webhooks (together with the nabu casa cloud) or have a vpn connection between your remote location and home so the remote esphome device can talk to your home assistant server directly.
Welcome.
Feel free to ask more questions if you are in need
Thanks, but the esphome device will be installed in other location diferent than where the home assistant is running. They are diferent houses, si my question is how connect the esphome device with a HA instance running far away using Internet
Thanks for your advices!!!
VPN is too complicated for my poor knowledge I think.
I have not nabu cloud, so the idea of expose my mqtt broker in Internet to be accesed from the esphome device location sounds me like the best solution for me.
Could you please tell me how to do it?
Can you set up a ddns service in your other house?
Not an MQTT solution…
I’m not a network or security expert.
Here are the settings to be made on the router where the remote device is installed:
1 - Configure a DDNS on the router (ex no-ip)
2 - Put fixed ip for the device
3 - Forward ports 6053 (api), 3232 (ota) and XXXX (web portal) to the ip configured in item 2.
I changed the web portal port, because the default is port 80 and when accessing it ends up opening the router settings, as I don’t know much about network, I changed the port to get around this problem.
The necessary settings in esphome are just wifi: use_address and web_server: port: xxxx, but I recommend adding all options below for security reasons.
Great walberjunior !!! This is something that I’m think I can do it by myself. If it works it can solve my problem!!!
I will test it in some days.
I have only a further question. I already have an integration of ESPhome running in my home for my local esphome devices with my normal wifi and the stardard settings (port and so on)
This integration can run in combination with another one to connect with the remote esphome devices in the other house?
Also no network or security expert here but I don’t think it is wise or smart to expose api, ota and web server ports to the outside of your local network. While the api has at least a transport encryption both ota and the web server are communicating in plain text to my knowledge. For a local network that can be acceptable but this shouldn’t be exposed to the world wide web at any means.
This is actually really bad and a potential security issue. Your routers configuration should never ever be accessible from outside of your local network.
One easier solution (let’s hope that reaches you before the censorship brigade raids this thread) is to make use of a webhook. If you would opt-in for the nabu casa cloud (which is worth any penny btw) that’s a one-click-setup essentially - if not you can still do this. Just need to figure out how exactly to do this in a safe matter as it will involve some configuration on your router for sure (probably best is to search the forum for a guide).
For the remote esphome device you just need one function which calls your webhook url in an interval (for example every minute). For that you will make use of the http request component combinded with time in esphome
You will probably end up with something like this in your esphome yaml:
This is actually really bad and a potential security issue. Your routers configuration should never ever be accessible from outside of your local network.
This is the fault of the ISP. I moved to a new house and the modem came configured this way, I still haven’t had time to see how to disable external access to the router.
After everything is working the OTA and WEB Server ports can be disabled. That way you will be less insecure.