remove retained MQTT message

You can remove retained messages by publishing a zero length retained message to the topic you wish to clear. For example, you could do it with mosquitto_pub as follows:

mosquitto_pub -t -r -n

 

From the Docs:


-r, --retain

If retain is given, the message will be retained as a “last known good” value on the broker. See mqtt(7) for more information.


-n, --null-message

Send a null (zero length) message.

Advertisements

Python virtualenv creation and activation for windows

A reminder mainly for myself on how to create and activate a virtualenv for use in Jupyter Notebook.

 

  1. Navigate to parent python directory
  2. Make the directory: virtualenv <envname>
  3. Move into the directory: cd <envname>
  4. Test activate the env: Scripts/Activate
  5. Install packages: pip install jupyter
  6. Install any other package you want: pip install pylutron-caseta
  7. Create batch file for launch: Jupyter Notebook on Windows

 

HomeAssistant Configurator Setup with Autostart

This is a supercool and easy way to edit your files from Home Assistant.  I have been juggling windows which isn’t bad but for remote work, a web interface is really nice.

WARNING: I am running HASS as root and this is not the recommended setup

Here is a screenshot of the final product:

Clipboard01

The initial steps are pretty easy.

Get the configurator and put the configurator.py file in your homeassistant directory.  In my case, it’s .homeassistant

Edit the configurator file if you need to put in the basepath and password:

Code for configurator.py file:

# Set BASEPATH to something like "/home/hass/.homeassistant/" if you're not running the
# configurator from that path
BASEPATH = "/root/.homeassistant/"

# If a password is required to access the API, set it in the form of “password”
# if you have HA ignoring SSL locally this is not needed if on same machine.
HASS_API_PASSWORD = “PASSWORD”

When you do this, You’ll find that the file runs in the foreground and it should be present after you add an iframe to the config (I have a love hate relationship with the iframe module, this is the first time it’s been useful to me).

Code for configuration.yaml file:

panel_iframe:
  configurator:
    title: 'Config'
    icon: mdi:wrench
    url: 'http://10.xxx.xxx.xxx:3218' 


NB: On my dev server, I set this to loopback 127.0.0.1 and it worked fine.
If you’re storing secrets like a HASS API password, you probably want to ignore configurator.py from your GIT backups.

Making the configurator.py run as a service:
navigate to /etc/systemd/system

nano ha-configurator@root.service

That file should look like this

[Unit]
Description=HASS-PoC-Configurator
After=network.target

[Service]
Type=simple
#Set the path to your configurator.py location
ExecStart=/usr/bin/python3 "/root/.homeassistant/configurator.py"

[Install]
WantedBy=multi-user.target

exit nano, saving it.

Then do the magic to make it a system service with autostart.

sudo systemctl --system daemon-reload
sudo systemctl enable ha-configurator@root.service
sudo systemctl start ha-configurator@root.service
sudo systemctl status ha-configurator@root.service

DietPi on a 2GB card with Raspberry Pi 3 Model B

I love DietPi.  My first SBC was a painful start which is saying a lot after coming from SoC.  I could not get Armbian running stable on the OrangePi Zero which was my first foray.

In retrospect, I should have bought the widely adopted RaspberryPi 3 but I was going for cheap, because I really didn’t know if HomeAssistant was going to be a workable system.  I figured that if I failed, I would just turn the board into a sensor node or a VPN server.

Well, the OP-0 has been working great.  I had cut my teeth on the OP and moved to RPi from Arrow (nice discount online).

I took a crack at my favorite lightweight OS for SBC, DietPi.  I found the stretch lite would do the job, but it was painful to configure EVERYTHING from scratch.  DietPi does the majority for you.

Wi-Fi

I did have hiccups getting it to connect to wifi.  At first I needed an external adapter to trigger WPA_supplicant and feed a password.  I was getting an error that said my PSK phrase was invalid.  The second install, I switched to my guest network and back and it connected no problem.  Weird.

Small SD Card Size

The next issue was the size of the SD card.  OrangePi Zero comes with only 256 or 512 MB of ram so it’s swap was accordingly small.   With the RPi’s more generous 1 GB of RAM, the swapfile that is automatically generated is equal in size.  There is an assumption on the part of the really awesome creators that you wouldn’t actually use a card so small.  It’s understandable and applies to the vast majority of users.

The solution is to go into the dietpi-config and under advanced change the swap file size.  I had to hunt around for it but found it and resized to 1/3 or 333 MB.  That should work for my experimental purposes.

The solution is outlined here.  

 

So I went from 48 MB usable space to

df -h

—> 800 MB free.  Yay.

 

 

 

 

 

 

Backing up an Asus RT-AC68U or Asus RT‑N66U “Dark Knight” Router

Some really phenomenal scripts have been made that would have definitely saved me some time and a lot of frustration migrating and restoring routers in the past.

most of what you need to know is in this thread.

The script can be run from USB and it will store the files in the directory from which it is run.

The basics are as follows:

  1. save the dowloaded scripts and unzip them to a directory
  2. move the directory to USB-I formatted the USB file system as FAT since that is widely usable.
  3. stick the USB in the router
  4. navigate to the directory where you put the script.
  5. cd nvram-save-r26.2
  6. and Run the command below to start it in backup mode.
  7. ./nvram-save.sh

There are other modes like migrate and verbose so you can see what’s happening.