Skip to content

Instantly share code, notes, and snippets.

@blakadder
Last active January 23, 2021 21:58
Show Gist options
  • Save blakadder/54460f6ec9db7e58fa1b1e173954e704 to your computer and use it in GitHub Desktop.
Save blakadder/54460f6ec9db7e58fa1b1e173954e704 to your computer and use it in GitHub Desktop.
hasp ha test
blueprint:
name: HASP Toggle Object
description: Link a HASP toggle object with an on/off entity
domain: automation
input:
target_entity:
name: Entity controlled by the button
description: Select an entity to bind with a pxbx toggle object.
selector:
entity:
topic:
name: Topic
page:
name: Page ID (px)
selector:
number:
min: 0
max: 12
mode: box
object:
name: Object ID (ox)
selector:
number:
min: 1
max: 200
mode: box
variables:
topic: !input topic
page: !input page
object: !input object
trigger:
- platform: mqtt
topic: 'hasp/+/state/+'
- platform: state
entity_id: !input target_entity
action:
- choose:
- conditions:
- condition: template
value_template: '{{ trigger.platform == "mqtt" and trigger.topic == "hasp/" + topic + "/state/p" + page + "b" + object + "" }}'
sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ trigger.payload_json.val == "0" }}'
sequence:
- service: homeassistant.turn_off
entity_id: !input target_entity
- conditions:
- condition: template
value_template: '{{ trigger.payload_json.val == "1" }}'
sequence:
- service: homeassistant.turn_on
entity_id: !input target_entity
- conditions:
- condition: template
value_template: '{{ trigger.platform == "state" }}'
sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ trigger.to_state.state == "on" }}'
sequence:
- service: mqtt.publish
data:
topic: 'hasp/{{topic}}/command/p[{{page}}].b[{{object}}].val'
payload: 1
- conditions:
- condition: template
value_template: '{{ trigger.to_state.state == "off" }}'
sequence:
- service: mqtt.publish
data:
topic: 'hasp/{{topic}}/command/p[{{page}}].b[{{object}}].val'
payload: 0
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment