oldsap
(oldsap)
1
i created a sensor in my sensor.yaml file like this:
platform: mqtt
state_topic: “maindoor/lastopened”
name: maindoorlastopened
i want sensor.maindoorlastopened to show the last time the door sensor was triggered using mqtt.publish. how do i go about doing it? thank you
francisp
(Francis)
2
try this :
- id: '1567689065684'
alias: maindoor opened
trigger:
- entity_id: binary_sensor.maindoor
platform: state
to: 'on'
action:
- data:
payload: '{{ now().strftime("%H:%M:%S") }}'
topic: 'sensor/maindoorlastopened'
service: mqtt.publish
1 Like
oldsap
(oldsap)
3
Thank you. I tried it but the sensor.maindoorlastopened state still shows Unknown.
oldsap
(oldsap)
4
I also tried topic: maindoor/lastopened
francisp
(Francis)
5
You probably need this :
- id: '1567689065684'
alias: maindoor opened
trigger:
- entity_id: binary_sensor.maindoor
platform: state
to: 'on'
action:
- data:
payload_template: '{{ now().strftime("%H:%M:%S") }}'
topic: 'sensor/maindoorlastopened'
service: mqtt.publish
1 Like
oldsap
(oldsap)
6
That works!
How do I show it on the front end? There must be something wrong with my sensor setup
SOLVED:
had to add value_template: ‘{{ now().strftime("%H:%M") }}’
thank you