Skip to content

Commit

Permalink
Prep for release v1.8.1
Browse files Browse the repository at this point in the history
- Repair temperature units regression (#82)
- Disk Used sensor repaired (was reporting free vs. used) (#83)
- Refine the advertisement of the command endpoints
  • Loading branch information
ironsheep committed Feb 27, 2023
1 parent 7828dce commit f08c88e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
17 changes: 10 additions & 7 deletions HA-ADVERT.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ For the purpose of this document we'll use the following to indicate where these

- placeholders used herein: `{HOSTNAME}`, `{BASE_TOPIC}`, and `{SENSOR_NAME}`.

**NOTE: author's setup**: I have a farm of 20+ RPi's spread all over my house. They all have identical **config.ini**'s. I ONLY set **"base\_topic"**, i do not set the other two. For the other two the default values work great.
**NOTE: author's setup**: I have a farm of 20+ RPi's spread all over my house. They all have identical **config.ini**'s. I ONLY set **"base\_topic"**, i do not set the other two. For the other two the default values work great.

## MQTT RPi Status Topics

Expand Down Expand Up @@ -88,13 +88,15 @@ The `~/monitor` advertisement:
"dev": {
"identifiers": ["RPi-e45f01Monf81801"],
"manufacturer": "Raspberry Pi (Trading) Ltd.",
"name": "RPi-{HOSTNAME}.home",
"name": "RPi-{HOSTNAME-FQDN}",
"model": "RPi 4 Model B r1.5",
"sw_version": "bullseye 5.15.84-v8+"
}
}
```

**NOTE**: *in this case you'll see that {HOSTNAME} is not used for the "name:" value. Instead we use the fully qualified domain name {HOSTNAME-FQDN}. On the authors' network (192.168.255.\*) the internal domain is ".home" so an RPi with the name say "pip2iotgw" has an FQDN of "pip2iotgw.home" On the author's network is it common then to say `ssh [email protected]` to log into the RPi.*

### The Temperature endpoint

The `~/temperature` advertisement:
Expand Down Expand Up @@ -200,11 +202,12 @@ The `~/shutdown` Command advertisement:

```json
{
"name": "Rpi Command {HOSTNAME} Shutdown",
"name": "Rpi Shutdown {HOSTNAME} Command",
"uniq_id": "RPi-e45f01Monf81801_shutdown",
"~": "{BASE_TOPIC}/command/{SENSOR_NAME}",
"cmd_t": "~/shutdown",
"json_attr_t": "~/shutdown/attributes",
"avty_t": "~/status",
"pl_avail": "online",
"pl_not_avail": "offline",
"ic": "mdi:power-sleep",
Expand All @@ -220,11 +223,12 @@ The `~/reboot` Command advertisement:

```json
{
"name": "Rpi Command {HOSTNAME} Reboot",
"name": "Rpi Reboot {HOSTNAME} Command",
"uniq_id": "RPi-e45f01Monf81801_reboot",
"~": "{BASE_TOPIC}/command/{SENSOR_NAME}",
"cmd_t": "~/reboot",
"json_attr_t": "~/reboot/attributes",
"avty_t": "~/status",
"pl_avail": "online",
"pl_not_avail": "offline",
"ic": "mdi:restart",
Expand All @@ -240,11 +244,12 @@ The `~/restart_service` Command advertisement:

```json
{
"name": "Rpi Command {HOSTNAME} Restart_Service",
"name": "Rpi Restart_Service {HOSTNAME} Command",
"uniq_id": "RPi-e45f01Monf81801_restart_service",
"~": "{BASE_TOPIC}/command/{SENSOR_NAME}",
"cmd_t": "~/restart_service",
"json_attr_t": "~/restart_service/attributes",
"avty_t": "~/status",
"pl_avail": "online",
"pl_not_avail": "offline",
"ic": "mdi:cog-counterclockwise",
Expand Down Expand Up @@ -280,5 +285,3 @@ The `~/restart_service` Command advertisement:
[maintenance-shield]: https://img.shields.io/badge/maintainer-stephen%40ironsheep.biz-blue.svg?style=for-the-badge
[releases-shield]: https://img.shields.io/github/release/ironsheep/RPi-Reporter-MQTT2HA-Daemon.svg?style=for-the-badge
[releases]: https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon/releases


15 changes: 9 additions & 6 deletions ISP-RPi-mqtt-daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ def getNumberOfAvailableUpdates():

def publishAliveStatus():
print_line('- SEND: yes, still alive -', debug=True)
mqtt_client.publish(lwt_topic, payload=lwt_online_val, retain=False)
mqtt_client.publish(lwt_sensor_topic, payload=lwt_online_val, retain=False)


def aliveTimeoutHandler():
Expand Down Expand Up @@ -1233,7 +1233,8 @@ def isAliveTimerRunning():
# -----------------------------------------------------------------------------

# MQTT connection
lwt_topic = '{}/sensor/{}/status'.format(base_topic, sensor_name.lower())
lwt_sensor_topic = '{}/sensor/{}/status'.format(base_topic, sensor_name.lower())
lwt_command_topic = '{}/command/{}/status'.format(base_topic, sensor_name.lower())
lwt_online_val = 'online'
lwt_offline_val = 'offline'

Expand All @@ -1242,7 +1243,8 @@ def isAliveTimerRunning():
mqtt_client.on_connect = on_connect


mqtt_client.will_set(lwt_topic, payload=lwt_offline_val, retain=True)
mqtt_client.will_set(lwt_sensor_topic, payload=lwt_offline_val, retain=True)
mqtt_client.will_set(lwt_command_topic, payload=lwt_offline_val, retain=True)

if config['MQTT'].getboolean('tls', False):
# According to the docs, setting PROTOCOL_SSLv23 "Selects the highest protocol version
Expand Down Expand Up @@ -1271,7 +1273,8 @@ def isAliveTimerRunning():
error=True, sd_notify=True)
sys.exit(1)
else:
mqtt_client.publish(lwt_topic, payload=lwt_online_val, retain=False)
mqtt_client.publish(lwt_sensor_topic, payload=lwt_online_val, retain=False)
mqtt_client.publish(lwt_command_topic, payload=lwt_online_val, retain=False)
mqtt_client.loop_start()

while mqtt_client_connected == False: # wait in loop
Expand Down Expand Up @@ -1388,7 +1391,7 @@ def isAliveTimerRunning():
iconName = 'mdi:cog-counterclockwise'
detectorValues.update({
command: dict(
title='RPi Command {} {}'.format(rpi_hostname, command),
title='RPi {} {} Command'.format(command, rpi_hostname),
topic_category='button',
no_title_prefix='yes',
icon=iconName,
Expand Down Expand Up @@ -1430,7 +1433,7 @@ def isAliveTimerRunning():
payload['json_attr_t'] = '~/{}/attributes'.format(params['command'])
else:
payload['~'] = sensor_base_topic
payload['avty_t'] = activity_topic_rel
payload['avty_t'] = activity_topic_rel
payload['pl_avail'] = lwt_online_val
payload['pl_not_avail'] = lwt_offline_val
if 'trigger_type' in params:
Expand Down

0 comments on commit f08c88e

Please sign in to comment.