Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear how to install this! #1

Open
richardcastle opened this issue Mar 21, 2022 · 10 comments
Open

Unclear how to install this! #1

richardcastle opened this issue Mar 21, 2022 · 10 comments

Comments

@richardcastle
Copy link

I'm a reasonably seasoned HA user and have installed several other 3rd party components using HACCs.

I have added the repository and found ha-internet_status and installed it, however after the reboot it's not clear what needs to be done next. I have attempted to use the "Add integration" list selector, however the component doesn't show here.

I've tried generating the configuration.yaml entries as described in the readme file, however HA borks with a configuration error (it doesn't recognise the internet_status parent key, and thus refuses to reboot etc.

Any suggestions as to what I'm doing wrong?! Your component looks awesome BTW!

@crowbarz
Copy link
Owner

Yes, this integration isn't configured through the UI and can only be configured via configuration.yaml.

It should be installable via a HACS custom repository, although I have never tried it. If it installs correctly, then within your custom_components directory you should find an internet_status sub-directory containing the integration code. If the integration is loaded, then HA displays a warning at startup:

2022-03-21 20:58:03 WARNING (SyncWorker_2) [homeassistant.loader] We found a custom integration internet_status which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant

Are you nesting the internet_status config under another entity section, eg. sensor? It should be configured right at the top level config, ie. at the same level as homeassistant or sensor.

I'm fairly sure that HA loads all custom integrations in custom_components on startup irrespective of whether they are configured. You can try restarting HA after installing but before configuring, then configure and check/restarting again to pick up the configuration. Alternatively, try hard rebooting the HA server to force the integration to load, but I didn't seem to need to do that when trying to replicate your issue on my dev 2022.3.3 install.

@richardcastle
Copy link
Author

Thank you so much for your quick response! I removed the install from HACCs and manually copied it across using a SAMBA share. This now appears to be loading as I get the telltale warning at the start of the log files. Excellent!

I'm using the stock example for configuration.yaml provided in the wiki, however i'm getting the following error:

Invalid config for [internet_status]: [isp_primary] is an invalid option for [internet_status]. Check: internet_status->internet_status->links->0->isp_primary. (See /config/configuration.yaml, line 9).

Formatting seems to be correct with double-space indentation etc. The entry sits just below the homeassistant: key and the block sits at the top level as requested.

I'll keep fiddling here to see what I'm doing wrong, but wanted to simply thank you at this stage for coming back to me so quickly. Richard

@crowbarz
Copy link
Owner

I just reviewed the example and realised that I didn't update README.md after release 0.6 (from 2020!) which changed the configuration format (back) to a list to allow specifying an arbitrary number of links.

Humble apologies for that - I hope you haven't spent too much time trying to get the old example to work :(

I'll push a change with an updated example now, but will also need to review/rewrite the rest of the page.

@richardcastle
Copy link
Author

Wonderful. We're up and running. I had even gone back to older builds in case there was a breaking change, but I don't think I went back far enough! Thanks again for the neat tool.

@crowbarz
Copy link
Owner

Glad to hear that it's working now.

Can I ask how you are using this integration? My own use case (as documented in the README) seems quite niche and uncommon.

@richardcastle
Copy link
Author

Feels similar to be fair. I have cable broadband as my main connection with a router offering an alt. WAN route. I have a 4G router as my failover network. This tool allows me to quickly see what WAN link is live and whether there is an issue within HA.

@richardcastle
Copy link
Author

Just to confirm, when you say the NAT IP address, is that the public IP address that you'd see when you use something like https://whatismyipaddress.com/
?

If my mobile provider uses different public addresses at each connection, how could I account for that in the config?

R

@crowbarz
Copy link
Owner

crowbarz commented Mar 24, 2022

Yes, the NAT IP is typically your public IP on an internet facing link.

You can configure the integration in one of two ways to cater for links that use dynamic IPs:

  1. If configured_ip is not configured, the integration will use the IP that is detected at integration start as the expected IP for the link if it is up. This generally works for fixed internet access (cable, DSL, etc.) as the IP changes fairly rarely, and assumes that the link is up when the integration is started.
  2. You can also configure a reverse_hostname string, which will translate the IP back to a name and check whether the specified string appears in the name and consider the link up if it is present. For example, reverse_hostname: virginm.net (as per the VPN link in the example config) would reverse lookup the detected IP for the link, and check whether 'virginm.net' appears in the result. You can look up the name for an IP address using the host, dig -x or nslookup commands.

There's currently no way to reset the detected configured IP when the IP changes without restarting HA. I have been thinking about creating a service for that, though this happens infrequently in my setup.

@boukamp
Copy link

boukamp commented Nov 5, 2022

I just wanted to thank @crowbarz for this awesome sensor!

Why I needed this sensor - and what it does for me:

We recently had network connection issues (NBN in Australia) that forced us to get a 4G Modem as backup. I was looking for a way to let my family know when we're on the expensive 4G connection and when we're back on our regular NBN connection. This sensor here made this possible!
So, now, when our NBN connection drops and we're switching to 4G automatically, the family get's a notification via speakers in our house telling them that we're on 4G and that internet activity should be limited (as data on 4G is expensive). A reminder is played at a set time interval, if the NBN connection is lost for longer. As soon as the sensor detects that we're back to our regular NBN connection, an announcement is played to inform everyone that they can resume their usual internet activity levels.
I love how quickly the sensor detects the switches.
Took me a while to figure out how to set it up - (I'm new to HA...) - but gladly @crowbarz provided some really helpful debugging settings that helped me figure out what I needed for my sensors.

The configuration steps:

So, here is some guidance for those interested in or struggling with the configuration:

In your configuration.yaml, add the sensor:

#### Fail-Over sensor based on the HA Internet Status at https://github.com/crowbarz/ha-internet_status
## Internet status configuration
internet_status:
  name: Internet Status
  entity_id: sensor.internet_status
  scan_interval: 30
  timeout: 3
  retries: 3
  links:
    - name: Primary ISP
      entity_id: binary_sensor.isp_primary_status
      link_type: primary
      probe_server: 216.239.38.10
      probe_type: google
      reverse_hostname: "yourISPsdomain.com.au"
      debug_probe: false
#      rtt_sensor:
#        entity_id: sensor.isp_primary_rtt
#        debug_rtt: false
    - name: Secondary ISP
      entity_id: binary_sensor.isp_secondary_status
      link_type: secondary
      probe_server: 216.239.38.10
      probe_type: google
      configured_ip: XXX.XXX.XXX.XXX
      debug_probe: false
#      rtt_sensor:
#        entity_id: sensor.isp_secondary_rtt
#        debug_rtt: false

(I didn't need the rtt sensors. Just left them in there as comments for future reference - in case I want to enable them later.)

The probe_server IP-address just needs to be an ip address outside your network that can return a ping. (I made the mistake to pick one that didn't have a ping service enabled at first.)
As I don't have a fixed IP address with my NBN Internet Service Provider, I'm relying on the reverse_hostname feature of this sensor. I wasn't quite sure what exactly to put into this field - but with some debugging, I was able to tweak the setting to what I needed. Further details below.

For the 4G connection, the reverse_hostname feature failed, as the IP of my 4G provider doesn't allow for a reverse hostname lookup in this context. I thus had to rely on a "configured_ip" which I set to the external IP of my 4G connection. Again, I was able to figure out that configured_IP value thanks to the debug feature.

So, now, let's quickly touch on the debugging..

Finding your IP address and/or hostname:

First I needed to add the following to my configuration.yaml to enable the logger and focus the logger on this sensor:

# System LOGGER 
logger:
  default: warning
  logs:
    # log level for Internet Status component
    custom_components.internet_status: debug

Next, I needed to set the debug_probe attributes of the two link objects to true. (See the first code section above - just change the debug_probe: true lines to debug_probe: false .

With these settings, I was able to reboot my HA instance and monitor the console output. In the output, I then found my reverse hostname, while I was connected to my NBN provider/my primary ISP. I copied that value into the configuration.yaml (in place of your_connections_hostname) - but instead of copying the entire hostname, I only copied the domain name part of the hostname. So, with a hostname like me-with-a-unique-number.yourISP.com.au, I just used reverse_hostname: "yourISP.com.au" in the configuration.yaml.
Next, I disconnected my primary internet connection and had my system running on the 4G connection. I thereby again monitored the console output of my HA instance and was able to get the IP value from that. (Look for log entries related to "[custom_components.internet_status.binary_sensor]"). So, if you find your IP to be 1.2.3.4, then just use configured_ip: 1.2.3.4 in the Seconary ISP link of your sensor.

Testing and wrapping up:

Finally, after another restart, I tested the sensor in my Home Assistant set up by unplugging my main network cable to force a fail-over to 4G, and plugging it back again. With the sensors reacting as I had hoped, I disabled the logging and the debugging (via the configuration.yamls) and started using the sensors in my automation. For example.:

alias: Announce NBN Change
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.isp_primary_status
condition:
  - condition: time
    before: "00:00:00"
    after: "07:00:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
action:
  - if:
      - condition: state
        state: "on"
        entity_id: binary_sensor.isp_primary_status
    then:
      - service: script.broadcast_announcement
        data:
          message: >-
            N B N is back online! Feel free to resume regular internet
            activity.
    else:
      - if:
          - condition: state
            entity_id: binary_sensor.isp_secondary_status
            state: "on"
        then:
          - service: script.broadcast_announcement
            data:
              message: >-
                N B N is offline! We switched to 4G. Please restrict online
                activity to necessities until the NBN connection has been
                recovered. Thank you.
        else:
          - if:
              - condition: state
                entity_id: binary_sensor.isp_secondary_status
                state: "off"
            then:
              - service: script.broadcast_announcement
                data:
                  message: >-
                    N B N is offline! The backup connection is dead, too. We are
                    completely offline, it seems.
            else:
              - service: script.broadcast_announcement
                data:
                  message: >-
                    N B N is offline! The status of the backup connection can
                    not be determined. If you are still connected, please
                    consider restricting online activity to necessities until
                    the NBN connection has been recovered. Thank you.
mode: single

I hope this helps some folks.

Again:
###A very big "Thank you!" to @crowbarz!

@crowbarz
Copy link
Owner

@boukamp thanks for the detailed write-up of your use case and your debugging steps, hopefully that will help others tailor a configuration to suit their particular multiple internet link setup. (And hopefully I'll find some time to overhaul the documentation at some stage too.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants