Using this python script for showing the last command (script in this setting),
id like to also show it the automations being triggered.
How would this script have to be adapted to do that:
# Get params
event = data.get('event')
# logger.error("LAST CMD: " + str(event))
# Sample: <Event call_service[L]: service_data=, service_call_id=78356624-86, service=mp_playpause, domain=script>
# Find the script name.
pos_start = event.find('service=')+8
pos_end = event.find(',', pos_start)
# Get the state object (script) from the name
entity_id = 'script.' + event[pos_start:pos_end]
state = hass.states.get(entity_id)
dt = datetime.datetime.now() #state.attributes.get('last_triggered') #
time = "%02d:%02d" % (dt.hour, dt.minute)
msg = []
try:
msg = state.name
except:
msg = ''
if (msg is None):
msg = ''
# Ignore some names
# msg = state.name
if (msg == 'None') or (msg.startswith('Set ')):
msg = ''
if (msg != '') :
# Sensor update
hass.states.set('sensor.last_command', '{}'.format( msg), {
# 'custom_ui_state_card': 'state-card-value_only',
# 'text': sensor_message,
'unit_of_measurement': 'Cmd',
'friendly_name': time,
'entity_picture': '/local/buttons/command.png'
})
the automation passing the script its data is as follows:
- alias: 'Call Service Event (Script)'
id: 'Call Service Event (Script)'
hide_entity: True
initial_state: 'on'
trigger:
platform: event
event_type: call_service
event_data:
domain: script
action:
- delay: 00:00:02
- service: python_script.last_cmd
data_template:
event: "{{ trigger.event }}"
Could i simply add another trigger here:
trigger:
- platform: event
event_type: call_service
event_data:
domain: script
- platform: event
event_type: call_service
event_data:
domain: automation
if so, the entity_id = 'script.' + event[pos_start:pos_end]
would still have to be adapted to include the automation, and have the state
include these and show the msg
Please have a quick look?
Cheers,
Marius