Calendar only working when "run"

Hi to all!

I have a very simple problem but i couldn’t found the solution.
I create an automation with simple time add:

alias: timestart
description: “”
trigger:

  • platform: time
    at: “12:53:00”
    condition: []
    action:
  • type: turn_on
    device_id: 8c920a6a0f7a3e30a6328dbb05ca04b7
    entity_id: b1f6ebad88e97012c7c6101dcce9a992
    domain: switch
    mode: single

This code is working well!

Next I create this code:

alias: Front Light Schedule
trigger:

  • platform: calendar
    event: start
    entity_id: calendar.locsolas
    condition: []
    action:
  • if:
    • “{{ trigger.event == ‘start’ }}”
      then:
    • type: turn_off
      device_id: 8c920a6a0f7a3e30a6328dbb05ca04b7
      entity_id: b1f6ebad88e97012c7c6101dcce9a992
      domain: switch
      else:
    • type: turn_on
      device_id: 8c920a6a0f7a3e30a6328dbb05ca04b7
      entity_id: b1f6ebad88e97012c7c6101dcce9a992
      domain: switch

This code is not trigger my relay, but when “push” “run” button in the automation, the trigger is working.

This is my calendar:
kép
I know the calendars are only updated every 15 minutes. I try to reload automations but nothing changes.
I set calendar to 16:41 and navigate to the created automation:


It’s seems to be working, but the relay could not turn off.

Welcome kazilewy!

First a favour: Could you post your code properly?

I don’t think it makes sense to do an if-else action when you only use one trigger. Please try the example from the docs (modified):


    trigger:
      - platform: calendar
        event: start
        entity_id: calendar.locsolas
      - platform: calendar
        event: end
        entity_id: calendar.locsolas

    action:
      - if:
          - "{{ trigger.event == 'start' }}"
        then:
          - service: switch.turn_off
            target:
              entity_id: switch.YOUR_SWITCH_ENTITY_ID
        else:
          - service: switch.turn_on
            target:
              entity_id: switch.YOUR_SWITCH_ENTITY_ID

Hi Pedolsky!

Thank U for your answer!

I tried your code, but not working.

alias: ujauto
trigger:
  - platform: calendar
    event: start
    entity_id: calendar.locsolas
  - platform: calendar
    event: end
    entity_id: calendar.locsolas
action:
  - if:
      - "{{ trigger.event == 'start' }}"
    then:
      - service: switch.turn_on
        target:
          entity_id: b1f6ebad88e97012c7c6101dcce9a992
        data: {}
    else:
      - service: switch.turn_off
        target:
          entity_id: b1f6ebad88e97012c7c6101dcce9a992
        data: {}
mode: single

This code is working,

alias: időmegadás
description: ""
trigger:
  - platform: time
    at: "16:24:00"
condition: []
action:
  - type: turn_on
    device_id: 8c920a6a0f7a3e30a6328dbb05ca04b7
    entity_id: b1f6ebad88e97012c7c6101dcce9a992
    domain: switch
mode: single

but only add time is not enough for me, to start and stop my solenoid.
For example I want to start the watering on monday 08:30 and stop at 9:32 and start on thursday 8:30 and stop at 9:32 etc.

Maybe do you know other method to schedule my solenoid?
My other problem is VL53L0X laser distance sensor.
This is a simple ino code, but I don’t know how to send data to Home assistant


#include <Wire.h>
#include <VL53L0X.h>

VL53L0X sensor;

void setup()
{
 // pinMode(9,INPUT_PULLUP);
 // digitalWrite(9,HIGH);
  Serial.begin(9600);
  Wire.begin();

  sensor.init();
  sensor.setTimeout(500);

  // Start continuous back-to-back mode (take readings as
  // fast as possible).  To use continuous timed mode
  // instead, provide a desired inter-measurement period in
  // ms (e.g. sensor.startContinuous(100)).
  sensor.startContinuous(1000);
}

void loop()
{
  int distance =sensor.readRangeContinuousMillimeters();
  //int distance =sensor.startContinuous(100);
  
 //distance = distance;
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.print("mm");
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

  Serial.println();
  delay(1000);
}

I read many description but no result. Can You help me?

This my original code:

#include <Ethernet.h>
#include <ArduinoHA.h>

#define LED_PIN1             9
#define LED_PIN2             8
#define BROKER_ADDR         IPAddress(192,168,1,108)
#define BROKER_USERNAME     "mqttuser" // replace with your credentials
#define BROKER_PASSWORD     "M*********1"

byte mac[] = {0x00, 0x10, 0xFA, 0x6E, 0x38, 0x4A};

EthernetClient client;
HADevice device(mac, sizeof(mac));
HAMqtt mqtt(client, device);

// "led" is unique ID of the switch. You should define your own ID.
HASwitch led("led");
HASwitch led2("led2");

void onSwitchCommand(bool state, HASwitch* sender)
{
if (sender == &led) {
  digitalWrite(LED_PIN1, (state ? HIGH : LOW));
   // sender->setState(state); // report state back to the Home Assistant
        // the switch1 has been toggled
        // state == true means ON state
    } else if (sender == &led2) {
      digitalWrite(LED_PIN2, (state ? HIGH : LOW));
   // sender->setState(state); // report state back to the Home Assistant
        // the switch2 has been toggled
        // state == true means ON state
    }

   // digitalWrite(LED_PIN1, (state ? HIGH : LOW));
   // sender->setState(state); // report state back to the Home Assistant
}


void setup() {
    pinMode(LED_PIN1, OUTPUT);
    digitalWrite(LED_PIN1, LOW);
    pinMode(LED_PIN2, OUTPUT);
    digitalWrite(LED_PIN2, LOW);

    // you don't need to verify return status
    Ethernet.begin(mac);

    // set device's details (optional)
    device.setName("Arduino");
    device.setSoftwareVersion("1.0.2");

    // handle switch state
   // led.onCommand(onSwitchCommand);
   // led.setName("My LED2"); // optional

       led.setName("ledlabel1new");
    led.setIcon("mdi:lightbulb");
    led.onCommand(onSwitchCommand);

    led2.setName("ledlabel2new");
    led2.setIcon("mdi:lightbulb");
    led2.onCommand(onSwitchCommand);   

    mqtt.begin(BROKER_ADDR, BROKER_USERNAME, BROKER_PASSWORD);
}

void loop() {
    Ethernet.maintain();
    mqtt.loop();
}

What is the automation trace telling you?

I’m not familiar with the other topic.

It is very simple. Turn the switch on at a specific day and time and turn it off at a specific day and time.

When you press the run button in the UI, it skips the triggers and conditions and only runs the actions. Your trigger does not run.

Ok, I assumed all the time that the automation is triggered by the calendar event… :expressionless:

That’s right. The calendar trigger not working.