I am trying to using an input_number so that I can vary the scan_interval time when I am refreshing the Maps from my Xiaomi when using Valetudo
I have tried to copy the bottom example using an input_number as a delay.
But I am getting an error when running it through the Configuration validation
Invalid config for [sensor]: offset 00:00:{{ states.input_number.mapdelay.state | int }} should be format âHH:MMâ or âHH:MM:SSâ for dictionary value @ data[âscan_intervalâ]. Got None. (See /config/configuration.yaml, line 61). Please check the docs at Sensor - Home Assistant
So I am a bit stuck, has anyone used an input_number before on a scan_interval or is it not possible?
Right, think I may have found part of the problem.
I have a decimal point and a zero after the number, probably need to figure out how to get rid of that?
Also, that attribute doesnât even exist for the rest sensor⌠not sure how you even got the idea to use that.
documentation:
available attributes for setup:
resource
(string)(Required)The resource or endpoint that contains the value.
Default value: string
method
(string)(Optional)The method of the request.
Default value: GET
name
(string)(Optional)Name of the REST sensor.
Default value: REST Sensor
value_template
(template)(Optional)Defines a template to extract the value.
payload
(string)(Optional)The payload to send with a POST request. Depends on the service, but usually formed as JSON.
verify_ssl
(boolean)(Optional)Verify the certification of the endpoint.
Default value: true
unit_of_measurement
(string)(Optional)Defines the units of measurement of the sensor, if any.
authentication
(string)(Optional)Type of the HTTP authentication. basic or digest.
username
(string)(Optional)The username for accessing the REST endpoint.
password
(string)(Optional)The password for accessing the REST endpoint.
headers
(list | string)(Optional)The headers for the requests.
json_attributes
(list | string)A list of keys to extract values from a JSON dictionary result and then set as sensor attributes.
force_update
(boolean)Sends update events even if the value hasnât changed. Useful if you want to have meaningful value graphs in history.
Default value: false
notice how scan_interval doesnât exist in the documentation?
If i have scan_interval: 30 it updates the image location every 30 seconds and if i use scan_interval: 3600 it updates once an hour. I can confirm that by the time stamp on the images on my Vacuum.
Itâs possible that the sensor base class has a scan_interval attribute/setup variable. But the fact still remains, templates can only exist in spots that allow templating.
Is there any other way of turning the rest sensor on / off?
Really I only want it to run once when HA starts up.
Then when my Vacuum is running turn the rest sensor back on again and have the scan_interval running at say 2 seconds so I have real time maps displayed.
I have tried putting the sensor in an automation but that didnât work.
The problem is, you canât change scan interval live. From my experience, it appears as if the scan interval is only built into the configuration and cannot be set during execution.
You may be able to do this in a python script. Meaning, create the sensor for a duration and then destroy it after itâs done.
Side question, why donât you want it updating every 2 seconds all the time? Then it will know immediately when itâs on, or do you have a separate sensor for on/off?
Couldnât you just stop the image creation process in Valetudo when the vacuum is off? I mean you could build valetudo into home assistant as a custom component and handle the on/off there.
If your vacuum is already rooted and you know what youâre doing just download the latest valetudo binary from the releases page and scp it to /usr/local/bin/ . Then grab the valetudo.conf from the deployment folder put it inside /etc/init/ run service valetudo start and youâre good. Donât forget to chmod +x the binary.
I think it would mean SSHâing into the Vacuum to turn on an off the webserver every time I wanted to clean so I could get the maps.
it would be possible to fork the github and change it so it self updated the maps in the folder only when cleaning. But I wouldnât know where to start.
Perhaps AppDaemon could be used instead to do the rest process?
Or would it behave the same as normal yaml and have the rest sensor polling the vacuum all the time?
Have you created a component before? The valetudo interface for the phone looked like it had a start/stop button. My assumption would be that the api has those methods as well.
Making a new component that has a start/stop service would suit your needs I think.
scan_interval is undocumented but valid for a RESTful sensor. However, youâre right, templates are not allowed there. And scan_interval is not an attribute of the sensor itself, so you canât even force a change there.
My recommendation would be to write either a âshell_commandâ or a âpython_scriptâ that, when run, will fetch the resource and store the data in a sensor.
Then make two automations⌠both of them call your new script. One of them has a time trigger of every 3600 seconds. The other, a time trigger of every 30 seconds. Use automation.turn_off and automation.turn_on to turn on the 30 second trigger automation whenever you need the more frequent updating.
# importing the requests library
import requests
# api-endpoint
URL = "http://192.168.x.x/api/remote/map"
# sending get request and saving the response as response object
r = requests.get(url = URL)
# extracting data in json format
data = r.json()
# extracting the second half of the map URL
imageurl = data['results'][0]['mapsrc']
# passing the output back to HASS
hass.services.call('entity_id:rosieurl', imageurl)
I donât actually know if I need the [âresultsâ][0] part of imageurl = data[âresultsâ][0][âmapsrcâ] though?
Yes, a python script is MOSTLY just normal python. However, it is a crippled python (in order to keep your script from doing âbad thingsâ, I presume).
So, among many other things⌠you canât use âimportâ. At all. Which will make this task difficult.
However, on the positive side⌠you can use a shell_script (instead of a python script) and that shell script can be in any language you want (including python), and itâll have none of the crippled aspects of python_script⌠but⌠itâll also not have access to any of the âeasy to useâ stuff that HASS Includes in its python libraries. Itâs completely standalone. So⌠to set a sensor, for instance, youâre going to have to call Home Assistantâs REST API.
I canât offer any input on what pieces of the json returned by the request you need because I have not seen the data nor do I know exactly what youâre trying to do. But⌠if you run this as a shell_command, that last line (hass.service.callâŚ) will need to be the place where you call the Home Assistant REST API instead.