Add Time-Scheduler

Thanks to your help, my first steps went very well.
I have a D1Mini here that controls my Led. Temperature/humidity works as well
Dimming, switching on/off the LEDs.

Now I want to add a timer for days, months and year.

I'm currently testing the light scheduler so that I can understand the function first. How to connect it and which nodes I might still need.

Can I connect the light scheduler directly to the mqtt nodes of the D1Mini.
I have 5 nodes (temperature, humidity, LED_1, LED_2, LED_3. I can switch and dim the LEDs but only manually.

Or do I need an additional switch here?
I thought, since I can already switch the LEDs from the dashboard, maybe I just need to put a scheduler in front of it and it will then switch the LEDs.
Is the?

Best regards

Hier ist der ESPHome Code vom D1Mini.
Vieles habe ich mir von einem Beispiel vom Benutzer TotallyInformation hier im Forum kopiert :slight_smile:

# D1 Mini Configuration for D1M05 (D1 Mini)

# Pins (=GPIO)| Input? | Output? | Comments
  # D0 = 16   | Y      | Y       | High @ boot, Wake, I/P: No Interrupt, O/P: No PWM or I2C
  # D1 = 5    | Y      | Y       | I2C SCL
  # D2 = 4    | Y      | Y       | I2C SDA
  # D3 = 0    | Y      | Y       | 
  # D4 = 2    | Y      | Y       | Onboard LED
  # D5 = 14   | Y      | Y       | 
  # D6 = 12   | Y      | Y       | 
  # D7 = 13   | Y      | Y       | 
  # D8 = 15   | Y      | Y       | 
  # RX = 3    | Y      | Y       | 
  # TX = 1    |        | Y       | 
  # A0 = ADC0 | Y      |         | 

substitutions: # All have to be strings, the substitution process will convert them to the correct types
  devicename: d1m01-kueche-anzuchtbox
  upper_devicename: D1Mini kueche Anzuchtbox
  device_location: Kueche
  device_description: Anzuchtbox Steuerung platform using ESPhome firmware
  mqtt_prefix: d1m01-kueche-anzuchtbox # $mqtt_root/$devicename # Argh! combined substitutions don't work!
  esp_board: d1_mini
  last_update: "2023-05-02 20:47:12"

  broker: !secret mqtt_broker 
  username: !secret mqtt_username
  password: !secret mqtt_password
  topic_prefix: AnzuchtBox
  id: mqtt_client

  power_save_mode: none # none (default for esp8266), light (default for esp32), high
  ssid: !secret WLAN_ASUS_SSID
  password: !secret WLAN_ASUS_PASSWORD
    static_ip: !secret D1MINI_KUECHE_ANZUCHTBOX_IP
    gateway: !secret WLAN_ASUS_GATEWAY_IP
    subnet: !secret WLAN_ASUS_SUBNET
    dns1: !secret WLAN_ASUS_DNS1
    #fast_connect: on
  ap: # Enable fallback hotspot (captive portal) in case wifi connection fails
    ssid: "Anzuchtbox Fallback Hotspot"
    password: !secret WIFI_AP_PASSWORD
  safe_mode: true
  password: !secret HA_OTA_PASSWORD

api: # Enable Home Assistant API
    key: "VI6xMzgYs40Sa9rs0r5xjMa1gAaGQzjMZL/HlASdHQ0="

  name: $devicename
  friendly_name: Grobot-AnzuchtBox
  platform: ESP8266
  board: d1_mini

# Festlegen der I2C Ports ESP32 und ESP8266 
  sda: 4      # Standard Port für ESP8266 GPIO4 sda
  scl: 5      # Standard Port für ESP8266 GPIO5 scl
  scan: true  # I2C Port_Scan Standard = true
  id: bus_a   # id = bei mehreren PCA9685

# pca9685 16 Channel PWM Multiplexer konfiguration
    id: pca9685_hub1            # id muss nur angegeben werden wenn mehrere PCAs vorhanden sind
    frequency: 1000             # für MW-LDD s sollten 1000 HZ (mögliche Werte 24 Hz bis 1525,88 Hz. Standard 1000Hz) Frequenz eingestellt sein
    address: 0x40               # HEX Adresse des PCA9685 , Standart = 0x40 (müsste in diesem Fall nicht mit angegeben werden)

  - platform: monochromatic
    name: "Anzuchtbox 2 x 3500K LED-Mitte"
    output: "PWM0"
    state_topic: AnzuchtBox/Light_Control/3500K_LED_Mitte
  - platform: monochromatic
    name: "Anzuchtbox 2 x 3500K LED-Links/Rechts"
    output: "PWM1"
    state_topic: AnzuchtBox/Light_Control/3500K_LED_L_R
  - platform: monochromatic
    name: "Anzuchtbox 4 x 5000K LED"
    state_topic: AnzuchtBox/Light_Control/5000K
    output: "PWM2"

# Festlegen der PWM Outputs 0-15 
  - platform: pca9685
    id: PWM0
    channel: 0                 # Kanal 0-15, wir benutzen den Kanal 4 = 5. Pin 0,1,2,3,4...
  - platform: pca9685
    id: PWM1
    channel: 1                 # Kanal 0-15, wir benutzen den Kanal 3 = 4. Pin 0,1,2,3,4...
  - platform: pca9685
    id: PWM2
    channel: 2                  # Kanal 0-15, wir benutzen den Kanal 4 = 5. Pin 0,1,2,3,4...

# Enable logging


# DHT22 Temp/Humidy Sensor
  - platform: dht
    pin: D0
    model: AM2302
      name: "Temperatur"
      id: temperatur
      state_topic: AnzuchtBox/DHT22/Temperatur
      name: "Luftfeuchtigkeit"
      id: luftfeuchtigkeit
      state_topic: AnzuchtBox/DHT22/Luftfeuchtigkeit
      accuracy_decimals: 1
      # filters:
      # - offset: 4.2

Yes, you should be able to. I think that sending to topic d1m01-kueche-anzuchtbox/AnzuchtBox/Light_Control/3500K_LED_Mitte for example, should control the PWM0 connection for example? Though you have them all set as output - is that right? I'm a bit rusty on ESPhome as I haven't made any amendments to mine in ages.

Yes exactly. I currently only have only 2 nodes for each query in Node-Red.
in-mqtt===>debug (this get the topic what you told me)

I want create now same in-mqtt with the same topic

(in the HA configuration.yaml I set up date-time. ! )
Edit: date-time not needm schedulers get date and time self

but the node scheduler has to send some value to the in-mqtt (to the topic ==> anzuchtbox/Anzuc.....), right?
If I have to send a value, what does the in-mqtt need for the esp ?

Bit busy so struggling to help. But I would probably trigger manually and see what the value is. Probably a zero or one but might be "On"/"Off" or "on"/"off" - or something else?

No problem... we can't all share. :slight_smile:
We only have 2 hands and feet.

I've now also got the BigTimer running under Node-Red, .... I thought. Also my other nodes where I thought they were working, everything was just virtual. They only worked on Node-Red.
At no time did I have these visible in the HA integrity menu.
Clear. I didn't have one either
Node Red Companion installed.
I just thought it worked because I saw all values, all LEDs and their status in the node-red menu. I also got my temperature readings.
My BigTimer works there too. It supposedly switches the ESPhome-D1Mini, I see the values ​​On/Off and thought great, I got it.

I didn't realize all this until I installed Node-Red Companion and didn't see any entities there.

The ESPhome-D1Mini only works because I configured it under ESPhome, saw it with its 6 entities in the HA integration menu and could/can use it.
Everything I've done in Node-Red so far shows me the status of the ESP-D1Mini correctly, but if the BigTimer switches something there, it's only in Node-Red, but it doesn't really switch the ESP.
I would like to post it here so you can see how it looks in node-red.
Thats mean, i don't understood how is work together and what i need for.
The BigTimer you can show the pic... conecetd already to esphome, he send also any off or on values to the esp-device... but i think only in node-red because the esp-device Grobot-AnzuchtBox not interested what he get from the BigTimer

i try to put her my node-red Flow's json-code

flows.json (6.7 KB)
and a pic about the flows and the HA-integrations
The ESP-Device Grobot-AnzuchtBox, iis there ready for use later in the dashboard... But only, because i created bevore already in ESPhome... all other like the BigTimer van't find not in the Integration from the Node-Red Companion.. i have all only in Node-Red self

Just been re-reading the ESPhome docs.

Have a read of the MQTT Client Component docs - you will see that any component that can use MQTT is able to specify state and command topics and what the defaults are.

There is also a separate MQTT Subscribe Sensor though that only understands numeric inputs.

I'm afraid that I don't currently have a device set up that has an externally controllable GPIO. I do, however, have a device that receives multiple MQTT inputs that come from other sensor platforms and displays temperatures and humidity from around the house on a small M5Basic device.

If you need more specific support, you should probably seek it from the ESPhome forum as the knowledge levels will be higher there.

That's where I read it too. Also with the subscribe... but it has a standard setting even if I didn't specify it.... at least that's how I understood it.
But I'll try it now with an explicit setting, we'll see...

That's why I didn't try further with the subscribe because ===> if I control the ESP via my HA frontend, i.e. switch on the LEDs and dim them. does that work too...
I will test it again with the Subscribe...
Thank you for the info and the help

I'll report when I've done it

Best regards

Maybe. But I don't use HA. I've tried it a few times but never found it worth the effort since I've already built everything I need using just Node-RED.

on my system run mqtt-explorer too
there I see what is sent when I switch the LEDs on or off (from the HA)

i use now the subscrib and text-subscribe but i'm not sure if that enough or right what i wrote there

# DHT22 Temp/Humidy Sensor
  - platform: dht
    pin: D0
    model: AM2302
      name: "Temperatur"
      id: temperatur
      state_topic: AnzuchtBox/DHT22/Temperatur
      name: "Luftfeuchtigkeit"
      id: luftfeuchtigkeit
      state_topic: AnzuchtBox/DHT22/Luftfeuchtigkeit
      accuracy_decimals: 1
      # filters:
      # - offset: 4.2
  - platform: mqtt_subscribe
    name: "Data from topic"
    id: TEST_ID
    topic: AnzuchtBox/DataSubscribeText/Light_Control/3500K_LED_Mitte

  - platform: mqtt_subscribe
    name: "Data from topic"
    id: TEST2_ID
    topic: AnzuchtBox/DataSubscribeText/Light_Control/3500K_LED_Mitte

But i don't know
know the
and the mqtt_subscribe
what he have to do with the message what he get

i try to ask some in a ESPhome form , because i think you have right... thats a esphome problem...
or i send the data wrong

Subscribe only takes numeric inputs as I think I said? You need the command topic.

ups... i tought the mqtt text_sensor: accept text command like a json.
ohh I read and understood that completely wrong.
that would explain everything.
okay l read this mqtt subscribe section again...
if not then i change this all and let talk both only over the home-assistant api:
because i thingk to understand... if i control the esp only over HA-device-manager then works fine and i think, this Home-Assistant device manager talk only HA api:

You can certainly do this without HA. I don't really have time to set up a test platform at the moment I'm afraid but I am pretty sure that you can use the command topic with a switch.

oh so sorry... you mean the
mqtt command_topic: livingroom/custom_command_topic

aha maybe thats the reason i hope

Oh my god... not think that... no... i have to do this... not make my job Jullian... you use a lot of time for me...
i'm self interested in that...
also if i can only use HA-api... i would like know why and how works mqtt with node-red and others... only then i understand more and more

I try now this all again... and i'm sure soon i find my big mistake

Best and a lot regards

ps... teh inforamtions what i get already from you... very important... and i come more and more clother to the my understanding-hole

That was exactly the right hint Julian,
Thanks very much. you saved my sunday

Now that I can switch the light.
I think schedulers like BigTimer can only send 1 topic. Correct?
I have e.g. 3 lamps here.
all schedulers that I saw, whether BigTimer or Light scheduler, can send only 1 topic
Is there a trick how to solve this?
like put any dispatcher-node between the scheduler and the msqtt-out

command_topic: AnzuchtBox/3500K_LED_L_R/custom_command_topic
command_topic: AnzuchtBox/3500K_LED_Mitte/custom_command_topic
 command_topic: AnzuchtBox/5000K/custom_command_topic

i saw now, maybe that's a function node


I think so. I stopped using it a long time ago. I use the sun-position nodes for simple or astro-related settings and CRON+ for complex needs. CRON+ Can output different topics.

cron-jobs tell me anything from my linux-time
ok, then maybe was my first thinking use a scheduler for more then one time-switches wrong.

only for understanding:
I hope I have the right idea.
Later I would like to be able to control and use everything in a frontend or on a mobile app.
So I'm looking for a way that I can do various cron jobs later very conveniently, e.g. via an e.g. Ha calendar app. The cron job is only the backend.
Do you think this is possible?
For example, if you control your controller with any information from sun-position , then maybe you also use a front-end app that packs the cron job and maybe a few ticks or offsets there, right?
or you change all what you need only in Node-Red ?

Just pointing out, in case you didn't realise, that Julian meant node-red-contrib-cron-plus.

sorry i mean same same... i remember only on the cron-job from linux... and thats i think configure in node-red like that...
sorry.. i wrote it wrong...but i mean and understood it already what he mean


Later i would like create a system like that...

Controlling my lighting will become very complex later.

But it should be easy to use on the frontend. Because my gardener would like only use a simple-using frontend

For example I want:
Light 1: will be switched on January 1st, 2024 at 8:00 a.m. with 75% power and off at 12:00 p.m. This should be every day until February 31, 2024. On March 1, 2024 at 8:00 with 100% on and off at 14:00.
This should run until June 30th. Then completely off.

light 2
Should run like a light 1 and
from 8:00 a.m. to 9:00 a.m. from 0-100% increasing and from 11:00 a.m. to 12:00 p.m. from 100-0% decreasing.

Later, lamps should only switch on after the UV radiation of the sun or be dimmed to certain percentage values.

The effect is:
Greenhouse lighting for various plants that are planted outside in the greenhouse and which, depending on the solar radiation and UV radiation, are given additional lighting, are always and at any time supplied with exactly the amount of light and UV radiation they need.

There are already all lot of good sensors on the market that measure UV radiation and UV intensity at every wavelength.

Thus, a gardener would always only need so much energy and thus give the plants the optimum amount of sunlight (lighting) in order to ultimately get the best possible yield for the lowest amount of energy.

If the plants are grown purely indoors, like in England in a tunnel or in an airplane hanger (I once saw it on TV), you could also use it for something like that. so you can use it anywhere.

thats mean:
i have to look now for the right Node-Red AddOns like cron-plus and any dimm-function. But all of that, later i would like control all on my HA frontend

sure sometimes i ask total stupid... i know.. sorry for that missunderstanding

CRON+ can output whatever you like and you can define as many criteria as you like. Here is an example:

Here I combine several different inputs from other sensors and buttons and use a function node for the output. But I also use a CRON+ node for daily on/off/brightness controls. Node-RED makes it easy to mix and match like this.

You will also note that I use a group environment variable so that I can easily copy/paste the CRON+ node into a different group for a different location.

In my case, all commands to physical devices go out via MQTT and the devices all take their commands from MQTT. (actually not quite true because I do still have some legacy devices. They still take commands from MQTT, but they are converted to legacy outputs in Node-RED).