Add Suspend to MQTT
chripede opened this issue · 9 comments
Describe the solution you'd like
I think being able to Suspend/Standby via MQTT would be great.
As a side note, I think it should be configurable if you want to be able to unlock a session via mqtt.
Hey @chripede thanks for the suggestion. I've just added suspend and hibernate commands via MQTT to the agent in version 7.2.0. Check it out!
Also note, you can create your own commands as needed (as long as what you want to do is something that can be triggered through D-Bus). However, I am still keen to add commands directly where they would be widely useful or common, so keep the suggestions coming (clicky here for a template for suggestions).
Thanks, I appreciate it.
I did have to remove my configuration and device to have it re-register in MQTT. Otherwise the new buttons didn't show up. This led me down the road of doing some testing:
Oh no @chripede, that's not good. Okay so one thing to try, make sure the agent is registered and you've enabled MQTT support in it. Then:
- Stop the agent.
- Run
go-hass-agent reset
. This will wipe the agent config but also wipe any agent config in MQTT. It's crucial you've enable MQTT in the agent before doing this, otherwise it won't remove any configuration from MQTT. - Run the agent again and re-register.
- Enable MQTT. Stop the agent.
- Restart the agent.
If that doesn't work, can you run the agent with trace logging enabled with go-hass-agent --trace
, let it run for a minute, then stop and attach the log located at ~/.local/state/go-hass-agent.log
?
Side note: It's a bit clunky I know to enable MQTT with the stop/start. I need to work out a good way to do this dynamically...
That does indeed fix it, but only until I restart Mosquitto and HA. Then the problem returns.
Maybe the agent should register mqtt on every start? Changing mqtt.registered
to false in preferences.toml fixes it when restarting the agent.
Hey @chripede, that's interesting. I restart my development environment running Home Assistant and Mosquitto all the time, and the controls stay. This is done by sending the configuration messages to the broker with a retained status requested. A broker should hold on to those messages across restarts and each time Home Assistant connects to the broker, the broker sends those retained messages to it.
I wonder if your Mosquitto instance is configured without any persistence between restarts? In that case, maybe it is ignoring the retained request or only storing it until next restart? Currently, the agent requires persistence enabled on the broker.
Hey. Yes, my mqtt is not set up with persistence - I'd prefer not to because some of my topics receives a lot of messages that needs no persistence.
Can I suggest that this agent registers mqtt on startup and also listens on homeassistant/status
to re-register every time it changes from offline
to online
?
Hey @chripede of course you can make a suggestion and yes I agree it will be better to have the agent work without needing persistence (which would also work with persistence anyway).
I will look to implement this in the next release. I'm going on a holiday shortly, so likely I won't get to this until sometime in April. But look out for the next release sometime that month in which I'll target this change!
I'm going to close this issue as the agent no longer requires persistence on the MQTT server and the suspend action is available.
If there is still something not working regarding the above, please re-open and we can continue to investigate.