add: only allow pulse when on schedule

This commit is contained in:
Tobias Reisinger 2020-08-27 10:46:52 +02:00
parent db7eb6305c
commit 14f93e44ce
4 changed files with 16 additions and 16 deletions

View file

@ -34,21 +34,25 @@ handler_loop(struct mg_connection *c_mqtt)
int is_on = 0;
int is_on_schedule = relay_is_on_schedule(relay, &time_now);
int pulse_relay = global_config.relay_configs[i].pulse_duration;
if(relay->is_on_schedule != is_on_schedule && relay->is_on_schedule != -1)
if(is_on_schedule)
{
relay->pulse_timer = global_config.relay_configs[i].pulse_duration;
if(pulse_relay)
{
is_on = 1;
--relay->pulse_timer;
LOGGER_DEBUG("relay %d is pulsing for %d more seconds\n", i, relay->pulse_timer);
}
else
{
is_on = 1;
LOGGER_DEBUG("relay %d is active\n", i);
}
}
if(is_on_schedule && !global_config.relay_configs[i].pulse_duration)
else
{
is_on = 1;
LOGGER_DEBUG("relay %d is active\n", i);
}
if(relay->pulse_timer > 0)
{
is_on = 1;
--relay->pulse_timer;
LOGGER_DEBUG("relay %d is pulsing for %d more seconds\n", i, relay->pulse_timer);
relay->pulse_timer = 0;
}
if(relay->is_on != is_on)
@ -68,7 +72,6 @@ handler_loop(struct mg_connection *c_mqtt)
--relay->sent_to_broker;
}
relay->is_on = is_on;
relay->is_on_schedule = is_on_schedule;
if(global_config.relay_configs[i].inverted)
{