Id like to check the output of several scripts actions to Mqtt topics, and hoped ot use a response variable like - repeat: count: > {{switches|count}} sequence: - variables: oid: > {{switches[repeat.index - 1]}} actueel: > sensor.{{oid}}_actueel totaal: > sensor.{{oid}}_totaal - action: mqtt.publish data: topic: > ha_main/sensor/{{oid}}/power_daystart payload: > {{states(actueel)|float(0)|round(2)}} qos: 2 retain: true response_variable: switches_pd
but that returns an error. Cant I do this, or am I using the wrong syntax. The error is somewhat cryptic to me
#Response_variable not accepted in script
1 messages · Page 1 of 1 (latest)
the mqtt.publish action doesn't provide response data
what would you expect it to respond?
the data 😉 I figured it would, because when I run it in the dev tools, the field is shown (albeit empty, and I figured that is because I didnt set the response variable..)
would you know a way to get that logged somehow?
or could we FR the addition to mqtt.publish ? seems reasonably useful for more generic use
But a MQTT push will not grab data. It does exactly what is says on the can, it only publishes data to MQTT. So there is nothing to return
A script can return data. But that's up to you in the script
Right, I see that. But dont see how should log those topic/payload in the repeat sequence. I could maybe use the write to log, but dont see the correct syntax doing that
preferably, Id have it in one file/card. notify file would be awesome
Why do you want to log it? What do you expect from it? Or what do you want to do with it?
Like I said, mqtt publish is just that, nicely publish it on the MQTT bus
smt like this:
- action: notify.send_message
target:
entity_id: notify.filed_mqtt_daystart
data:
message: >
{ topic: >
ha_main/sensor/slimme_meter/{{oid}}/daystart
payload: >
{{states(entityId)|round(2) if has_value(entityId) else 0}} }```
id want that, so I dont need to fire the mqtt explorer, and can check the correct output format
But how is it linked to MQTT? Only that it is the same data as you try to send to the MQTT bus?
Because you, you can just add a notify action to that repeat loop. But that notification should
Example with persistant notification:
description: ""
mode: single
triggers: []
conditions: []
actions:
- repeat:
count: |
{{switches|count}}
sequence:
- variables:
oid: |
{{switches[repeat.index - 1]}}
actueel: |
sensor.{{oid}}_actueel
totaal: |
sensor.{{oid}}_totaal
- action: mqtt.publish
data:
topic: |
ha_main/sensor/{{oid}}/power_daystart
payload: |
{{states(actueel)|float(0)|round(2)}}
qos: 2
retain: true
response_variable: switches_pd
- action: persistent_notification.create
metadata: {}
data:
message: |
Topic: ha_main/sensor/{{oid}}/power_daystart
payload: {{states(actueel)|float(0)|round(2)}}
An action will provide response data in that field in devtools > actions even if you do not provide response_variable in the action. You can try it out with an action like weather.get_forecasts
ended up with ```
- if:
condition: state
entity_id: input_boolean.file_mqtt_topics
state: 'on'
then:
action: notify.send_message
target:
entity_id: notify.filed_mqtt_daystart
data:
message: >
topic: {{oid}}
payload: {{states(actueel)|float(0)|round(2)}}