Time trigger parameters from mqtt

Hello everyone!
It is possible to get parameters for time trigger from MQTT topics?
For example, I have a topic, contains time when toggle light.
Is it posible push this data from mqtt topic to trigger configuration?

One of the way it’s code some script, which subscribe to this topic, get data from his topc and rewrite automations.yaml file with new parameter for time trigger and after that reload HA. But this solve is not so good, I think. Maybe HA already have some more propely solve? I just newbie with HA.

Hello Timofey,

Welcome to the forum. Let’s see if I can be of any assistance.

As I read this, I feel I need to understand what it is you are attempting to do. What is your goal.
There is an FAQ to help you understand the kind of info and how to present it for the best results so we can help you here:
https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question.

Also there are lots of topics for new and seasoned HA users alike on this page.
The Home Assistant Cookbook - Index.

I suggest checking some of that out and asking your question again stating what you are trying to do and we’ll see if we can help you.

I have Nextion HMI panel, from this HMI I can see some information, can control devices, toggle light, sockets, e.g.
Also I have linux controller with mqtt broker and HA. All devices I connect to MQTT broker, so I did mqtt integration in HA.
When I touch some widget in Nextion HMI this data pushes into mqtt boker, and light is toggle fro example and in HA I also see results of this action ofcourse.

So in HMI I have page, where I can configuration time periods for toggle heater.
For example, I can set time range from 13:00 for 18:00 when heater is ON, in other times it’s OFF.
So, question is can I put it configuration for time trigger in HA?

Post the MQTT topic that contains the scheduled time. Also post an example of what that scheduled time value looks like.

Right now, I don’t yet have tops and example values in them, as it’s a work in progress.

There should be a start time for the heater and a time when it turns off. There will probably be two tops, one with the start time and one with the end time.

/devices/heater_area/controls/heater_on_time
/devices/heater_area/controls/heater_off_time

Speaking about the format of the time data, I can realize it in different formats, for example in this one: “HH:MM:SS”, the main thing is that it should be clear for HA. But it is not clear how to put it into HA from mqtt.

Here’s one way to do it.

Create two MQTT Sensors, one for start time and the other for stop time.

mqtt:
  sensor:
    - name: Heater Start Time
      state_topic: "/devices/heater_area/controls/heater_on_time"
      device_class: timestamp
      value_template: "{{ today_at(value) }}"
      unique_id: hmi_start_time

    - name: Heater Stop Time
      state_topic: "/devices/heater_area/controls/heater_off_time"
      device_class: timestamp
      value_template: "{{ today_at(value) }}"
      unique_id: hmi_stop_time

Your automation can then use Time Triggers that reference the two sensors directly (because they’re timestamp sensors).

alias: example
trigger:
  - id: 'on'
    platform: time
    at: sensor.heater_start_time
  - id: 'off'
    platform: time
    at: sensor.heater_stop_time
condition: []
action:
  - action: 'switch.turn_{{ trigger.id }}'
    target:
      entity_id: switch.your_heater
1 Like

Thank you very much!
I will try to do it

It is work perfectly! Thanks a lot!

1 Like