Skip to content

kcapp/kcapp2mqtt

Repository files navigation

logo

kcapp2mqtt

Repository to forward events from kcapp onto MQTT

Development

  1. Install node dependencies
npm install
  1. Run with
DEBUG=kcapp* node kcapp2mqtt

Events

The following events are defined and will be pushed to MQTT when they happen

# Match
kcapp/matches/<match_id>/events/match_started
kcapp/matches/<match_id>/events/match_finished
kcapp/matches/<match_id>/events/match_cancelled

# Leg
kcapp/matches/<match_id>/legs/<leg_id>/events/leg_started
kcapp/matches/<match_id>/legs/<leg_id>/events/leg_cancelled
kcapp/matches/<match_id>/legs/<leg_id>/events/leg_finished

# Throws
kcapp/matches/<match_id>/legs/<leg_id>/events/throw
kcapp/matches/<match_id>/legs/<leg_id>/events/undo_throw

Schema

### match_started
Emitted when a new match begins.

match_type_id: int
match_mode_id: int
---

### leg_started
Emitted when a new leg begins.

leg_type_id: int
starting_score: int
---

### throw
Emitted for every throw.

id: int
player_id: int
first_dart:
  value: int
  multiplier: int
second_dart:
  value: int
  multiplier: int    
third_dart:
  value: int
  multiplier: int
is_bust: boolean
is_checkout: boolean
darts_thrown: int
player_color: string
---

### leg_finished
Emitted when a leg is completed.

winner_id: int
throw:
  first_dart:
    value: int
    multiplier: int
  second_dart:
    value: int
    multiplier: int    
  third_dart:
    value: int
    multiplier: int
player_color: string
---

### match_finished
Emitted when a match is completed.

winner_id: int
player_color: string

Docker

docker-compose file is provided to easily get up and running. Simply create a .env file with connection details to kcapp and MQTT. See the .env-dist file for examples

Home Assistant

If you are using Home Assistant, you can make automations to react to events happening within kcapp like the following

Leg Won Automation Example

alias: kcapp Leg Won
description: "Automation to run when a leg is won in kcapp"
triggers:
    - trigger: mqtt
        options:
        topic: kcapp/matches/+/legs/+/events/leg_finished
# Optionally, add a input_boolean to easily enable/disable the celebration
#conditions:
#    - condition: state
#        entity_id: input_boolean.dart_celebration
#        state:
#            - "on"
#        alias: Is celebration enabled?      
actions:
    # Create a temporary scene, so we can restore the lights when we are done celebrating
    - action: scene.create
        metadata: {}
        data:
            snapshot_entities:
            - light.dartboard_light
            # ... Add any additional lights you will be changing
            scene_id: temp_dart_celebration
    - action: light.turn_on
        data:
            rgb_color:
                - 56
                - 87
                - 26
            brightness_pct: 100
            flash: long
        target:
            entity_id:
            - light.dartboard_light
            # ... Add all lights you want to blink
    # Delay to let the blinking finish
    - delay:
        hours: 0
        minutes: 0
        seconds: 16
        milliseconds: 0
    # Return all the lights to their previous state
    - action: scene.turn_on
        metadata: {}
        target:
            entity_id: scene.temp_dart_celebration
        data: {}

Set lights to color of winning player

alias: kcapp Set lights to winner color
description: "Set the lights to the color of the winner"
triggers:
  - trigger: mqtt
    options:
      topic: kcapp/matches/+/legs/+/events/leg_finished
actions:
    # ...
    - action: light.turn_on
        data:
            brightness_pct: 100
            rgb_color: |
                {% if trigger.payload_json.player_color == "#dfdfdf" %}
                    [0, 255, 0] # Default to green if no color is set
                {% else %}
                    [{% set r = (trigger.payload_json.player_color[1:3] | int(base=16)) %}{{ r }},
                    {% set g = (trigger.payload_json.player_color[3:5] | int(base=16)) %}{{ g }},
                    {% set b = (trigger.payload_json.player_color[5:7] | int(base=16)) %}{{ b }}]
                {% endif %}
        target:
            entity_id: light.dartboard_light
    # ...

180 scored Automation Example

alias: kcapp 180 scored
description: Automation to run when a 180 is thrown
triggers:
    - trigger: mqtt
        options:
        topic: kcapp/matches/+/legs/+/events/throw
    conditions:
    - condition: template
        value_template: |
        {{ trigger.payload_json.first_dart.multiplier == 3 and 
            trigger.payload_json.first_dart.value == 20 and 
            trigger.payload_json.second_dart.multiplier == 3 and 
            trigger.payload_json.second_dart.value == 20 and 
            trigger.payload_json.third_dart.multiplier == 3 and
            trigger.payload_json.third_dart.value == 20 }}
actions:
    # Add your desired actions

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors