Miio / turn xiaomi gateway alarm ON/OFF

Hi,

Using the miio npm package users can trigger the gateway alarm on/off with these commands

miio protocol call <id> set_arming '["on"]'
miio protocol call <id> set_arming '["off"]'

How to implement it on HA ?
If the xiaomi gateway is addedd to HA using the token then we only need to set the payload to send to the gateway :

Get alarm state
{‘id’: XXX, ‘method’: ‘get_arming’, ‘params’: [’’]}
then the gateway send the {‘result’: [‘off’], ‘id’: XXX}

Set alarm state :

{‘id’: XXX, ‘method’: ‘set_arming’, ‘params’: [‘on’]}
{‘id’: XXX, ‘method’: ‘set_arming’, ‘params’: [‘off’]}

I don’t have skills to add these options but it worked well when I added some calls on

Let me know if you ahve any questions

I am not sure how to trigger what you are attempting, however have you considered using the generic alarm panel and configuring an automation to watch for state changes for your sensors resulting in the gateway emitting an alarm? That is what I have setup. I can post the config if you are interested.

1 Like

Yes, thank you, your config woud hepl me !
Thanks !

from configuration.yaml:

alarm_control_panel:
  - platform: manual
    name: Home Alarm
    code: xxxx
    pending_time: 30
    delay_time: 20
    trigger_time: 4
    disarmed:
      trigger_time: 0
    armed_home:
      pending_time: 0
      delay_time: 0
- alias: Trigger alarm while armed away
  trigger:
  - platform: state
    entity_id: sensor.front_door
    to: open
  - platform: state
    entity_id: binary_sensor.door_window_sensor_158d0001bb334e
    to: 'on'
  - platform: state
    entity_id: binary_sensor.living_motion_12
    to: 'on'
  - platform: state
    entity_id: binary_sensor.sitting_motion_16
    to: 'on'
  - platform: state
    entity_id: binary_sensor.garage_motion_13
    to: 'on'
  condition:
  - condition: state
    entity_id: alarm_control_panel.home_alarm
    state: armed_away
  action:
    service: alarm_control_panel.alarm_trigger
    entity_id: alarm_control_panel.home_alarm
  id: e69ccae17b5246edbe00670528186556
- alias: Trigger alarm while armed home
  trigger:
  - platform: state
    entity_id: sensor.front_door
    to: open
  - platform: state
    entity_id: binary_sensor.door_window_sensor_158d0001bb334e
    to: 'on'
  - platform: state
    entity_id: binary_sensor.garage_motion_13
    to: 'on'
  condition:
  - condition: state
    entity_id: alarm_control_panel.home_alarm
    state: armed_home
  action:
    service: alarm_control_panel.alarm_trigger
    entity_id: alarm_control_panel.home_alarm
  id: 0399e928e2e24c77bcb64df35060d88a
- alias: Send notification when alarm triggered
  trigger:
  - platform: state
    entity_id: alarm_control_panel.home_alarm
    to: triggered
  action:
  - service: xiaomi_aqara.play_ringtone
    data:
      gw_mac: 7811dcb9e148
      ringtone_id: 0
  - service: tts.google_say
    entity_id: media_player.home_group
    data:
      message: ALARM ALARM ALARM.
  - service: notify.Pushbullet
    data:
      message: The Alarm has been set off

the above is from my automations.yaml, unfortunately formatting is not working correctly if I type in the field.