Help with coding for day of the week check

Thanks for your reply.
I appli your code and it give me:

- id: '1593642521028'
  alias: Aspirateur
  description: ''
  trigger:
  - platform: template
    value_template: 'value_template: "{{ states(''sensor.date_time'') == (states.input_datetime.heure_passage_aspirateur.attributes.timestamp
      | int | timestamp_custom(''%H:%M'', True)) }}"'
  condition:
    {% if not is_state('input_select.aspi_'+nameday, 'Aucun')%}      #check if a script is selected in the inputselect
  action:
  - data:
      service_template: "script.{{ states('input_text.nameday') }}"      #launch the script

nameday is a sensor value who gives the name of the day (tuesday for exemple)
there is something wrong in the condition but i can’t make it work.

  condition:
    condition: template
    value_template: "{{ not is_state('input_select.aspi_'+nameday, 'Aucun') }}" 

:thinking:

where’s nameday coming from

it’s a date sensor:

      nameday:
        entity_id: sensor.date
        value_template: "{{ now().strftime('%A') }}"

but it isn’t declared in the template.

Hello,
thanks but it’s not working :cold_sweat:

- id: '1595359780476'
  alias: Programme Aspirateur
  description: ''
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == states(''input_datetime.heure_passage_aspirateur'')[0:5]
      }}'
  condition:
    condition: template
    value_template: "{{ not is_state('input_select.aspi_'+nameday, 'Aucun') }}" 
  action:
  - data:
      message: it work
    service: notify.notify

image
name of the input select of today:input_select.aspi_wednesday

You can’t just put nameday in the template. It would need to be:

  value_template: "{{ not is_state('input_select.aspi_'+(states('sensor.nameday')|lower), 'Aucun') }}"

If you use that nameday sensor in a similar fashion elsewhere, it might be better to put the lowercase filter in the sensor:

nameday:
  entity_id: sensor.date
  value_template: "{{ now().strftime('%A')|lower }}"

fyi, filters do not require parenthesis, it’s redundant. Filters are always applied to the object that precedes them.

1 Like

Hallelouya!!! it seem’s to work without the ( like petro said many thank’s
the lower case was already in the sensor config file but thanks for the tip.

1 Like

Why is now().strftime(’%w’) = 4 and now().weekday() = 3, thus off by 1 day? What am I missing here?

%w is based on Sunday being 0, now().weekday() is based on Monday being 0.