display home assistant wake on lan switch when argument --hass is used (#97)
This commit is contained in:
@@ -39,6 +39,8 @@ The easiest way to track your Raspberry Pi or Ubuntu computer system health and
|
|||||||
|
|
||||||
## What is new
|
## What is new
|
||||||
|
|
||||||
|
* 2024-03-24: --hass to display configuration for Home Assistant wake on lan switch
|
||||||
|
* 2024-02-20: Shutdown button added (only works when running as service)
|
||||||
* 2024-02-05: System Restart button added (only works when running as service)
|
* 2024-02-05: System Restart button added (only works when running as service)
|
||||||
* 2024-01-28: Remote updates via Home Assistant are now available
|
* 2024-01-28: Remote updates via Home Assistant are now available
|
||||||
* 2024-01-28: Improved error handling for the MQTT connection
|
* 2024-01-28: Improved error handling for the MQTT connection
|
||||||
@@ -61,6 +63,7 @@ options:
|
|||||||
--service, -s run script as a service
|
--service, -s run script as a service
|
||||||
--version, -v display version
|
--version, -v display version
|
||||||
--update, -u update script and config
|
--update, -u update script and config
|
||||||
|
--hass, -H display Home assistant wake on lan configuration
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -232,6 +235,8 @@ python3 src/update.py
|
|||||||
|
|
||||||
If you are using discovery_messages, then this step is not required as a new MQTT device will be automatically created in Home Assistant and all you need to do is add it to a dashboard.
|
If you are using discovery_messages, then this step is not required as a new MQTT device will be automatically created in Home Assistant and all you need to do is add it to a dashboard.
|
||||||
|
|
||||||
|
Use '''python3 src/rpi-cpu2mqtt.py --hass''' to display the configuration for Home Assistant wake on lan switch.
|
||||||
|
|
||||||
[moved to wiki](../../wiki/Home-Assistant-Integration-(outdated))
|
[moved to wiki](../../wiki/Home-Assistant-Integration-(outdated))
|
||||||
|
|
||||||
## To Do
|
## To Do
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ discovery_messages = True
|
|||||||
# Enable remote restart button in Home Assistant
|
# Enable remote restart button in Home Assistant
|
||||||
restart_button = True
|
restart_button = True
|
||||||
|
|
||||||
# Enable remote shutdiwb button in Home Assistant
|
# Enable remote shutdown button in Home Assistant
|
||||||
shutdown_button = True
|
shutdown_button = True
|
||||||
|
|
||||||
# Binary sensor that displays when there are updates
|
# Binary sensor that displays when there are updates
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ import re
|
|||||||
import html
|
import html
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
# get device host name - used in mqtt topic
|
|
||||||
hostname = socket.gethostname()
|
|
||||||
|
|
||||||
def check_wifi_signal(format):
|
def check_wifi_signal(format):
|
||||||
try:
|
try:
|
||||||
@@ -546,7 +544,8 @@ def parse_arguments():
|
|||||||
parser.add_argument('--display', '-d', action='store_true', help='display values on screen', default=False)
|
parser.add_argument('--display', '-d', action='store_true', help='display values on screen', default=False)
|
||||||
parser.add_argument('--service', '-s', action='store_true', help='run script as a service, sleep interval is configurable in config.py', default=False)
|
parser.add_argument('--service', '-s', action='store_true', help='run script as a service, sleep interval is configurable in config.py', default=False)
|
||||||
parser.add_argument('--version', '-v', action='store_true', help='display installed version and exit', default=False)
|
parser.add_argument('--version', '-v', action='store_true', help='display installed version and exit', default=False)
|
||||||
parser.add_argument('--update', '-u', action='store_true', help='update script and config then exit', default=False)
|
parser.add_argument('--update', '-u', action='store_true', help='update script and config then exit', default=False)
|
||||||
|
parser.add_argument('--hass', '-H', action='store_true', help='display Home assistant wake on lan configuration', default=False)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.update:
|
if args.update:
|
||||||
@@ -573,6 +572,22 @@ def parse_arguments():
|
|||||||
print("No update available")
|
print("No update available")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
if args.hass:
|
||||||
|
hass_config = """Add this to your Home Assistant switches.yaml file:
|
||||||
|
|
||||||
|
- platform: wake_on_lan
|
||||||
|
mac: "{}"
|
||||||
|
host: "{}"
|
||||||
|
name: "{}-switch"
|
||||||
|
turn_off:
|
||||||
|
service: mqtt.publish
|
||||||
|
data:
|
||||||
|
topic: "homeassistant/update/{}/command"
|
||||||
|
payload: "shutdown"
|
||||||
|
""".format(get_mac_address(), get_network_ip(), hostname, hostname )
|
||||||
|
print(hass_config)
|
||||||
|
exit()
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
@@ -640,8 +655,6 @@ def update_status():
|
|||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def on_message(client, userdata, msg):
|
def on_message(client, userdata, msg):
|
||||||
global exit_flag, thread1, thread2
|
global exit_flag, thread1, thread2
|
||||||
print("Received message: ", msg.payload.decode())
|
print("Received message: ", msg.payload.decode())
|
||||||
@@ -673,6 +686,8 @@ def on_message(client, userdata, msg):
|
|||||||
exit_flag = False
|
exit_flag = False
|
||||||
stop_event = threading.Event()
|
stop_event = threading.Event()
|
||||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
# get device host name - used in mqtt topic
|
||||||
|
hostname = socket.gethostname()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = parse_arguments();
|
args = parse_arguments();
|
||||||
|
|||||||
Reference in New Issue
Block a user