Need a little help with sensor

Hey guys

i need a little help with adding a sensor, i read on the community that creating a sensor by using a curl command is only creating a temporary one.which causes an problem :slight_smile:

Now here’s what i’m trying to do

I’,m using Motion : ( http://www.lavrsen.dk/foswiki/bin/view/Motion/WebHome ) to manage some usb camera and i managed to configure some swithc in HA to stop saving the the files using a command line switch and some automation. this works perfectly.

but now what i’m struggling with is a post action from motion to tell HA when a motion is detected on the webcam.

What i’ve tried to date is to create a curl command from Motion to HA
> curl -X POST -H "Content-Type:application/json" https://mydomain.net/api/states/sensor.cam_motion?api_password=XXXXXX -d '{"attributes": {"friendly_name": "Motion sensor Cam intérieur"}, "state": "on"}'

Which works fine and gives me a sensor in HA ( temp one )

But then i’m trying to get the last update time / date from it and i can’t manage to get it as the states.sensor.xxx…last_updated. doni’t work as i expected , probably due to a the temp sensor.

So , anyone of you would have a better idea to receive the state of the motion detection and be able to build some automation from it.

any idea , anyone , i’m open to try any suggestions :slight_smile:

thanks guys

Yo dude I hope that’s not your real API password!

Also do you have your configuration yaml where that sensor is configured? You should always post that as well! (without any passwords tho)

~Cheers

:fearful: thanks @fabaff for the edit …

This is exactly my problem @PhyberApex , there is no sensor configuration as it’s created but the curl post and that creates a temporary sensor which will disappear if i restart HA which is acceptable for the case i have .

the sensor appear though behave as the others , it’s displayed in the FE and it can be reached through the api

and it’s created using the curl post command above. nothing else.

This is why i’m asking if there is a better way , as i think this , even if it seems to work , might not have all that is needed to be used in automation ( like detecting when it was last updated , etc … )

Why not create one like this?

sensor:
    cam_motion:
      value_template: >-
        {{ states("sensor.cam_motion") }}

~Cheers

Tried it and does not seems to do much , looking at the state tab , nothing gets created ( device wise )
Did not know you could add a sensor without specifying a platform though ! it’s te case ?

Thanks @PhyberApex

Yeah you did not know because it should not be possible because apparently I am not able to do a simple copy paste…sorry. It should be:

sensor:
  - platform: template
    sensors:
      cam_motion:
        value_template: >-
          {{ states("sensor.cam_motion") }}

See here:

Edit:
You could also add itself to entity_id mentioned in the documentation to reduce workload I guess.

~Cheers

Yeah you did not know because it should not be possible because apparently I am not able to do a simple copy paste…sorry. It should be:

sensor:

  • platform: template
    sensors:
    cam_motion:
    value_template: >-
    {{ states(“sensor.cam_motion”) }}
    See here:

home-assistant.io1

Template Sensor

Instructions how to integrate Template sensors into Home Assistant.

Edit:
You could also add itself to entity_id mentioned in the documentation to reduce workload I guess.

~Cheers

I’ll check it out after work tonight , thanks @PhyberApex and post back here with my findings

1 Like

@PhyberApex , tested it all out since yesterday without success , when i make an http post to any sensor, it does not change the last updated or last changed value .
So
I changed my strategy

I made a small bash script that touch a local file when movement is detected , then i configured a command_line sensor that monitor the modification date / time of the file

This works perfectly and now i can automate my stuff based on that sensor. The only caveat is that it takes around 1 min to refresh the sensor value but i can live with that :slight_smile:

thanks for all the help !!

Cheers

1 Like

Thanks for letting us know what you did to achieve your goal and good work!

~Cheers