Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 96123

Passing MQTT payload into a delay and then some

$
0
0

@Bazmundi wrote:

Running home-assistant under docker on HypritOS. Works a treat.

Just learning this HA evironment though.

Learning task is that I have an ESPHome device I built and I can turn 4 relays on the board on/off from HA switches. Tested and working perfectly thanks.

What I want to do is send an MQTT topic to HA, on receipt HA turns on the ESPHome relay on (and therefore a relay on the board). Using the same MQTT topic, use the payload to set a HA timer/delay and then turn the ESPHome switch off after the delay/timer times out.

Using the developer MQTT tool I can currently turn the ESPHome switch on by publishing on the required MQTT topic, HA then turns the switch on via an Automation set by the HMI. So far so good.

Using the HA HMI to develop automations then, what is the means to take the MQTT payload (in milliseconds) and pass it to a delay (in seconds). I probably have the same problem with Scripts? That is I still need take the MQTT payload, pass it into a script, convert milliseconds to seconds and then set a delay and then an action to turn MQTT switch off.

In my configuration.yaml I have:

switch:
  - platform: mqtt
    name: MQTT Zone 1
    command_topic: "/os/12614780/1/1"
    value_template: '{{value_json.number / 1000}}'

“MQTT Zone 1” now appears in my widgets.

I built ESPHome automation and can toggle the MQTT Zone 1 switch at the HMI to toggle the ESPHome relay. Whoohoo!

I don’t seem to be able to get the MQTT Zone 1 switch to toggle via an MQTT topic using the setup in the configuration file.

I appear to be getting the error:

Value cannot be processed as a number: <state switch.mqtt_zone_1=off; friendly_name=MQTT Zone 1, assumed_state=True @ 2020-01-11T10:15:28.827275+10:30> (Offending entity: off)

So, the /1000 is trying to convert from milliseconds to seconds. The value was set to NUMBER in node-red. The actual topic with payload is:

/os/12614780/1/1/300000

I assume I am not understanding something about the value_template definition as explained in the associated help file.

Once I do get the value in the payload, I will want to get that into a timer that will turn the relay in the ESPhome off.

So and some point I will need to understand how to get the value out of the payload and into the delay.

I have dabbled with and automation as a numeric state with the MQTT switch as the entity delivering the value but I guess that won’t pan out until I get the payload value sorted.

So, first things first, any hints please on how to correct the value_template so that the topic actually delivers the value from the MQTT switch?

Cheers,
B

Posts: 5

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 96123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>