Frustration with set_datetime

Seems like every time I try to use set_datetime, I run into all sorts of barriers.

      - type: custom:button-card
        template: newlightbtn
        color: var(--primary-color)
        entity: sensor.humidifiers_last_cleaned
        name: 'Last cleaned:'
        icon: fapro:humidifier
        custom_fields: #None
        show_state: true
        tap_action:
          action: call-service
          service: input_datetime.set_datetime
          target:
            entity_id: input_datetime.humidifier_last_cleaned
          data:
            date: |

No matter what input I use after ‘date:’, HA throws a “must contain at least one of date, time, datetime, timestamp” error. Templating notation, javascript, all manner of strftime, etc… it all fails.

Using the developer tools/services tab, a call of ‘{{states(’‘sensor.date’’)}}’ actually fires off properly, but as soon as I drop it into the yaml file it fails.

I refuse to believe I have to set up a separate script to make this simple call, which suggests I’m missing something very fundamental. Any advice?

-J

The custom button card supports JavaScript templates. Not jinja templates.

https://github.com/custom-cards/button-card#javascript-templates

Templates in general only work in the configuration, not lovelace/ui. The only exception to the rule is the Markdown card, which supports jinja templates.

As @tom_l stated, the custom button card only accepts javascript templates.

You’ll most likely need to create a script to handle this unless you want to learn javascript.

Lastly, the javascript templates don’t work in every field on the custom button card. Off the top of my head, I don’t believe tap_action sub fields accept javascript templates, but I could be miss remembering.

There’s a list of fields that support templates in the link I posted. This cryptic entry is there:

Everything field in *_action

sounds like it is supported in tap_action and hold_action then

Experimentation reveals this:

      - type: custom:button-card
        template: newlightbtn
        color: var(--primary-color)
        entity: sensor.humidifiers_last_cleaned
        name: |
          [[[
            return states['sensor.date'].state;
          ]]]
        icon: fapro:humidifier
        custom_fields: #None
        show_state: true
        tap_action:
          action: call-service
          service: input_datetime.set_datetime
          target:
            entity_id: input_datetime.humidifier_last_cleaned
          data:
            date: |
              [[[
              return states['sensor.date'].state;
              ]]]

The ‘name’ field now comes back exactly as one would expect: ‘2019-09-09’. However, using that same code within the date: field results in the same “must contain as least one of…” error.

The format of the date should be correct to feed into the set_datetime service, shouldn’t it?

-J

should be service_data, per the docs for tap_action & hold_action.

Success!

        tap_action:
          action: call-service
          service: input_datetime.set_datetime
          service_data:
            entity_id: input_datetime.humidifier_last_cleaned
            datetime: |
                [[[
                  return states['sensor.date'].state;
                ]]]

So my primary problem was not paying enough attention to the button-card documentation, specifically the service_data tag and subsequent inclusions. As noted by a few above, javascript templates work just fine underneath any of the *_action calls it seems.

Thanks very much to every who jumped in on this thread; it is genuinely appreciated.

-J