Timestamp sensor not displayed

So I have this template to monitor a non-smart dryer. The goal is to keep track of the timestamp the dryer completes its cycle. I already have a sensor to track the status of the dryer based on consumption, but the timestamp sensor is not updated (or not displayed? I don’t know!)

This is the trigger template:

  - trigger:
    - platform: state
      entity_id: dryer.dryer_status
      to: "Done"
    sensor:  
      - name: dryer_last_cycle_end
        device_class: timestamp
        unique_id: dryer.dryer_last_cycle_end
        state: "{{ now() }}"

I think the sensor is populated because if I put this in the Developer Tools → Template I can see {{ now() }} is correctly converted to a timestamp, but if I put the sensor in a card, the output is “Unknown”

I am also pretty sure about the dryer.dryer_status transition to “Done” as I use it in automation for notifications, and it works.

Please feel free to correct any wrong assumption I made, as I started using HA a copule of months ago

Thanks

Check in Developer Tools → States, is this state actually capitalised?

Rest of the template looks ok, assuming you have it in the right place.

Also you know you can use capital letters and spaces in names right?

Both of these produce the same entity id:

name: dryer_last_cycle_end
name: Dryer Last Cycle End

The second one will look better on your dashboards though.

Yes, It is capitalized

Wow no, I didn’t know about this! the force of habit!

By the way, can It be an indentation problem?

# Examples I saw online
- trigger:
    - platform: state

# My template
- trigger:
  - platform: state

It is wise to pick a standard (two spaces) for indentation and stick to it but as long as you are consistent within each block it is ok. So no that is not your issue.

Has the dryer status changed from something to Done?

Indeed I need to be consistent with indentation, but what I was talking about was this:

This is a template I found in internet (reformatted for my purpose):

  - trigger:
      - platform: state
        entity_id: dryer.dryer_status
        to: "Done"
    sensor:  
      - name: dryer_last_cycle_end
        device_class: timestamp
        unique_id: dryer.dryer_last_cycle_end
        state: "{{ now() }}"

and you can see the dash before “platform” is under the i of “trigger”, while on mine:

  - trigger:
    - platform: state
      entity_id: dryer.dryer_status
      to: "Done"
    sensor:  
      - name: dryer_last_cycle_end
        device_class: timestamp
        unique_id: dryer.dryer_last_cycle_end
        state: "{{ now() }}"

You can see the dash before “platform” is under the t of “trigger”


The status sensor changes to “Done” at the end of every cycle

image

Yours is not ideal but is fine. As each block has consistent indentation. e.g.

OK:

- something: # this is a block of yaml with consistent indentation
  - petunias
  - a_whale
  - fortytwo
- something_else: # this is a completely separate block of yaml with consistent but different indentation
      - trillian
      - marvin
      - slartibartfast

This is not OK:

- something: # this is a block of yaml with inconsistent indentation
   - petunias
  - a_whale
  - fortytwo
- something_else: # this is a completely separate block of yaml also with inconsistent indentation
      - trillian
     - marvin
   - slartibartfast
1 Like

Ok I found the problem,
I referenced the entity_id in the trigger with the unique_id and not with the entity_id

# Not Working
  - trigger:
      - platform: state
        entity_id: dryer.dryer_status # using the wrong unique_id
        to: "Done"
    sensor:  
      - name: dryer_last_cycle_end
        device_class: timestamp
        unique_id: dryer.dryer_last_cycle_end
        state: "{{ now() }}"
# Working
  - trigger:
      - platform: state
        entity_id: sensor.dryer_status # using the correct entity_id
        to: "Done"
    sensor:  
      - name: dryer_last_cycle_end
        device_class: timestamp
        unique_id: dryer.dryer_last_cycle_end
        state: "{{ now() }}"