MQTT alarm state retention

Hi everyone

I have my paradox alarm setup using the mqtt middleware mentioned in this thread:

This is all working well except for one thing - when Home Assistant restarts the alarm state shows as Unkown and I am therefore unable to control the alarm until the state is manually changed (Either in the developer tools or by arming and disarming the alarm)

The configuration is set with “retain” as “true” :

alarm_control_panel:
 - platform: mqtt
   name: "Paradox"
   state_topic: "Paradox/HA_AlarmState"
   command_topic: "Paradox/C/P1"
   payload_disarm: "Disarm"
   payload_arm_home: "Sleep"
   payload_arm_away: "Arm"
   retain: True

The topics in the middleware are also setting the retention flag:

client.publish(Topic_Publish_HA_AlarmState, HA_Message , qos=0, retain=True)
client.publish(Topic_Publish_English_AlarmState, English_Message , qos=0, retain=True)

What could I be missing?

This only sets messages sent by HA with the retain flag.

In order for HA to receive the last message sent by your alarm system, your alarm system must set the retain flag on messages it sends.

You will have to look that up, as I no nothing about that system.

Thanks gpbenton

The middleware is already doing that - it sends the retain=True flag in the MQTT message:

client.publish(Topic_Publish_HA_AlarmState, HA_Message , qos=0, retain=True)

Check to see if the broker has retained the message in its database. The easiest way to use another client, and see what prints out at start up when you subscribe to all topics. I generally use mosquitto_sub

$ mosquitto_sub -h hassbian.local -t "#" -v
/energenie/eTRV/Command/ValveState/296 2
/energenie/eTRV/Command/ValveState/329 2
/energenie/eTRV/Command/ValveState/5460 2
/energenie/eTRV/Command/Temperature/329 16.0
/energenie/eTRV/Command/Temperature/296 21.0
/energenie/eTRV/Command/Temperature/5460 15.0

If you don’t see anything, then the broker hasn’t retained anything and you need to check your broker set up. For instance, the embedded broker doesn’t (or at least didn’t the last time I tried) support retained messages.

Thanks gpbenton

I am using a standalone mosquitto service.
It looks like it is retained in mosquitto as this is the output I get:

[homeassistant@hypnos ~]$ mosquitto_sub -h localhost -t “#” -v
Paradox/State State Machine 4, Listening for events…
Paradox/Zone/MAINBEDROOM OFF
Paradox/Zone/PASSAGEPIR ON
Paradox/Zone/DINING PIR OFF
Paradox/Zone/KITCHENDOOR OFF
Paradox/Zone/DONWSTAIRSPIR OFF
Paradox/Zone/GARAGEPIR OFF
Paradox/Zone/BACKBEAM OFF
Paradox/Zone/FRONTDOOR OFF
Paradox/Zone/BEDROOMBEAM OFF
Paradox/HA_AlarmState disarmed
Paradox/English_AlarmState Disarmed
Paradox/Partition OFF 1546183077
Paradox/C/P1 Disarm

This is the topic in question:

Paradox/HA_AlarmState disarmed

im not 100% but im using a mqtt alarm panel in HA and all my qos is set to 2 in not sure if that would make a difference for your situation

Hi Nath

I think you are 100% correct. I had just changed the qos to 1 in the middleware python script and now it seems to have retained the correct status after a reboot / restart:

client.publish(Topic_Publish_HA_AlarmState, HA_Message , qos=0, retain=True)

to

client.publish(Topic_Publish_HA_AlarmState, HA_Message , qos=1, retain=True)

Will continue to monitor to confirm this was the solution.

Thanks both for your help!

1 Like

yeah ideal dude keep us informed will be interesting to see how you get on.

OK so update - Confirmed this works through several restarts of the Home Assistant Service (Which it wasnt before)
It doesnt work through the restart of the mosquitto service itself. So when the server reboots for any reason the state is lost.
Trying to read if this is something that can be set in mosquitto. Anyone have any ideas?

What is your current mosquitto configuration file?