App-mqtt2job
view release on metacpan or search on metacpan
lib/App/mqtt2job.pm view on Meta::CPAN
payload: |-
{
"cmd": "[% cmd %]",
"args": "[% args %]",
"dt": "{{ now().strftime("%Y-%m-%d %H:%M:%S") }}",
"task": "[% task %]",
"status": "queue"
}
mode: single
=====================================================================
SENSORS: (configuration.yaml)
=====================================================================
sensor:
- name: "[% task %] status"
state_topic: "[% base_topic %]/status/[% task || "unknown" %]"
value_template: "{{ value_json.status }}"
- name: "[% task %] datetime"
state_topic: "[% base_topic %]/status/[% task || "unknown" %]"
value_template: "{{ value_json.dt }}"
- name: "[% task %] message"
state_topic: "[% base_topic %]/status/[% task || "unknown" %]"
value_template: "{{ value_json.msg }}"
- name: "[% task %] elapsed"
state_topic: "[% base_topic %]/status/[% task || "unknown" %]"
value_template: "{{ value_json.elapsed }}"
- name: "[% task %] output"
state_topic: "[% base_topic %]/status/[% task || "unknown" %]"
value_template: "{{ value_json.last_line }}"
=====================================================================
CARD: (dashboard, uses button-card from HACS)
=====================================================================
type: custom:button-card
show_state: false
custom_fields:
[% task %]_status:
card:
type: custom:button-card
entity: sensor.[% task %]_message
name: [% task %]
show_icon: true
icon: mdi:circle
state:
- value: ok
color: green
icon: mdi:check-circle
- value: failed
color: red
icon: mdi:alert-circle
- operator: default
color: blue
icon: mdi:progress-clock
tap_action:
action: navigate
navigation_path: [% task %]
styles:
custom_fields:
[% task %]_status:
- padding: 5px
- font-size: 12px
grid:
- grid-template-areas: "\"[% task %]_status\""
- grid-template-columns: 1fr 1fr
- grid-template-rows: auto
card:
- padding: 10px
- width: auto
- height: auto
=====================================================================
WIDGET: (hidden dashboard)
=====================================================================
title: [% task %]
path: [% task %]
icon: mdi:widgets
type: panel
cards:
- type: entities
entities:
- entity: sensor.[% task %]_datetime
- entity: sensor.[% task %]_elapsed
- entity: sensor.[% task %]_message
- entity: sensor.[% task %]_status
- entity: sensor.[% task %]_output
subview: true
_HA_CFG_TPL
return \$tpl;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
App::mqtt2job - Helper module for mqtt2job
=head1 VERSION
version 0.03
=head1 SYNOPSIS
mqtt2job --mqtt_server mqtt.example.com --base_topic my/topic --job_dir /apps
=head1 DESCRIPTION
Subscribes to the my/topic/job mqtt topic and upon receiving a
correctly formatted json message will fork and run the requested
job in a wrapper script providing it is present and executable in
the job_dir directory.
This wrapper will generate two child mqtt messages under the base
topic, at my/topic/status. Message one is sent when the job is
initiated. The second is sent when the job has completed (or timed
( run in 1.476 second using v1.01-cache-2.11-cpan-b16cb0d3907 )