MQTT JSON to HA Sensor assistance required

I have just setup this interface to grab status info and control my commercial alarm system. The data is being published to my MQTT broker (on my HA server) which I can monitor using the Google Chrome MQTT Lens app. What I don’t know how to do (despite reading the docs) is how to convert that info into sensors within HA, and also how to properly publish MQTT commands in JSON to allow HA to control my alarm system.

I tried a simple sensor as below but it caused the entire MQTT platform in HA to fail on startup…

sensor:
  - platform: mqtt
    name: Paradox Alarm Status
    state_topic: "paradoxdCTL/status"

I have read a bunch of other threads but I am still stumped on how to do it. Anyone good with this stuff that can help out?

The docs on that device are a bit light. No information on the format of the messages sent to any of the topics other than for paradoxdCTL/in.

You’re going to have to use mqtt-explorer (or another mqtt client) to view the messages in the other topics (particularly paradoxdCTL/status and maybe paradoxdCTL/out ).

Indeed…

When I used MQTT Lens to subscribe to all the topics listed in that Git repo, the paradoxdCTL/status topic simply showed ‘disarmed’, and the paradoxdCTL/out would spit out heaps of data every time I walked in front of a PIR sensor for example. It would essentially show that sensor going ‘open’ and then ‘closed’ again, all in a JSON message. I’ll have to copy some examples in here. Where it gets even harder is if I use one of the remote controls to arm / disarm the alarm system, it spits out about 5 different lots of JSON data…but essentially saying which area was armed.

Ok, so I have made some awesome progress on this since someone thankfully posted some info on the main Git repo for the interface I’m using.

Now I have the Paradox Alarm system status being tracked by HA and I have created 2 automations to get HA to ‘follow’ the Paradox Alarm status: arm HA when the Paradox alarm arms, and disarm HA when Paradox disarms…but I’m sure it could be done better and need a little template assistance please.

Currently I have the below 2 automations:

automation:
  - alias: 'HA alarm arm with Paradox alarm'
    trigger:
      platform: mqtt
      topic: paradoxdCTL/hassio/Arm
      payload: 'armed_away'
    action:
      - service: alarm_control_panel.alarm_arm_away
        entity_id: all

  - alias: 'HA alarm disarm with Paradox alarm'
    trigger:
      platform: mqtt
      topic: paradoxdCTL/hassio/Arm
      payload: 'disarmed'
    action:
      - service: alarm_control_panel.alarm_disarm
        entity_id: all
        data:
          code: 1111 #not really my code, don't stress out

…but I figure this can be turned into one, so I tried this:

automation:
  - alias: 'HA alarm arm with Paradox alarm'
    trigger:
      platform: mqtt
      topic: paradoxdCTL/hassio/Arm
    action:
      - service_template: >
          alarm_control_panel.alarm_{{ trigger.to_state.state }}
        entity_id: all

…but that didn’t work. Wondering if someone can help me get this working with a service template and just the one automation.

This would be a very nice set forward, then I just need to work out the correct mqtt message to send from HA to arm/ disarm the Paradox alarm so the integration works in both directions.

  1. When you call a service like alarm_control_panel.alarm_arm_away it should be targeted to a specific entity_id, namely an alarm_control_panel component, and not all entities within Home Assistant.

  2. The third automation uses an MQTT Trigger and then attempts to use trigger.to_state.state which is for State Trigger. The correct form is trigger.payload.

  3. Why are automations being used to arm/disarm? The MQTT Alarm Control Panel integration is designed for this purpose.

and unless I’m missing something it also won’t work because the template won’t resulkt in the correct service regardless of using state or payload.

the payloads are “armed_away” and “disarmed”. the services need “…arm_away” & “…disarm”. you need to drop the ed from the payloads to call the correct services.

the entity_id: all code was something that got added a fair while ago because HA stopped accepting the service call without it… from memory its needed.

I already have the normal HA alarm system integration and not sure how to also include MQTT to it… that said, it’s actually a custom alarm

Yes, all was added and is the preferred way to do it. However, leaving entity_id blank was simply deprecated and not eliminated (and it generates a warning message).

Proof:
From the services page, I called the service input_boolean.turn_on without specifying an entity_id. The result is all the input_booleans are now on and this warning message appears in the system log:

2019-07-23 22:05:35 WARNING (MainThread) [homeassistant.helpers.service] Not passing an entity ID to a service to target all entities is deprecated. Update your call to input_boolean.turn_on to be instead: entity_id: all

This was done on my test system (where the input_booleans don’t control anything important), running 0.96.3.

Well… ideally you need to use your alarm’s entity (something like alarm_control_panel.house by default?), but currently ANY instance of that integration responds to service calls so it doesn’t really make any difference (and yes, you can call the service without entity_id, it just generates warning but executes the code as well).

However, the plan is to change the code so it reacts only if the entity_id belongs to the entity. That’s why it would be better to use appropriate entity_ids in your automations.

But maybe the most important bit is that I wouldn’t recommend to combine arm and disarm in one automation for clarity reasons. Imho it’s better to have them in two separate automations and use !secret variables to share topic etc.