Updating "TIME INPUT" with a GET request

Hello,
I am trying to set the “time input” widget values via a get request in order to set it with the google assistant in my phone with the help of “ifttt” app
i manged to update a virtual pin that way but i cannot manage to update the time input widget values
what is the right way (syntax)
i tried some thing like this:
http://blynk-cloud.com/4ae3851817194e2596cf1b7103603ef8/update/V10?startAt=300&stopAt=3900&tz=“Europe/Kiev”&days=“1,2,3”
but it didnt work for me

thanks in advance

You can’t combine a variable and the data in this API format… try using just the data. Also you need the value= after the vPin?

http://blynk-cloud.com/4ae3851817194e2596cf1b7103603ef8/update/V10?value=300,3900,“Europe/Kiev”,“1,2,3”

And then change your AUTH code so others don’t mess with your project :stuck_out_tongue:

Thanks

So, did it work?

it worked only one time and stopped working

it updated the timer but not with the correct values it set it up to start 00:05 stop 00:05 and no days were chosen.
now it doesnt work at all

So it worked or not, that one time?

If the issue was the interpretation of your values, then I recommend experimenting until you understand what is needed, both in value and positioning in the command. Focus on one value at a time, EG startAt until it works, then stopAt, and so on.

Also, don’t forget to change your Auth Code… who knows what others are sending to mess up your settings :stuck_out_tongue:

:astonished: who do such a thing?! :smirk:

hi thanks
actually now i dont think it worked
it isnt my actual auth code :-p

1 Like

You need to do it like this:

http://blynk-cloud.com/auth_token/update/Vx?value=aa%00bb%00cc%00dd%00ee

aa - start time in seconds (OR sr - sunrise, ss - sunset)
bb - stop time in seconds
cc - timezone (written in words)
dd - days selected (separated by commas)
ee - timezone offset in seconds

Eg:

http://blynk-cloud.com/auth_token/update/V1?value=sr%003723%00Europe/London%001,5,6,7%003600

3 Likes

wauuuu!!! Thank you very much it works perfectly.
how did you knew to use “%00”? where is it written?

%00 is a null character when encoded in URL,

But I found it in another thread on here - use search, find answers :wink:

Edit: Thread here

Thank you, but i meant were is it specified that i should use a null character

I don’t think it is. But it works :smile:

Edit: I found it, will post tomorrow as I’m not near a PC at the moment. It’s not written in documentation but it is in the code :wink:

You are a GENIUS!!!

1 Like

Code as promised is here:

@Override
    public boolean updateIfSame(int deviceId, short pin, PinType type, String value) {
        if (super.updateIfSame(deviceId, pin, type, value)) {
            String[] values = value.split(BODY_SEPARATOR_STRING);
            if (values.length > 2) {
                startAt = calcTime(values[0]);
                stopAt = calcTime(values[1]);
                tzName = StringToZoneId.parseZoneId(values[2]);
                if (values.length == 3 || values[3].isEmpty()) {
                    days = null;
                } else {
                    String[] daysString = values[3].split(",");
                    days = new int[daysString.length];
                    for (int i = 0; i < daysString.length; i++) {
                        days[i] = Integer.parseInt(daysString[i]);
                    }
                }
            }
            return true;
        }
        return false;
    }

    private static int calcTime(String value) {
        switch (value) {
            case "ss" :
                return SUNSET;
            case "sr" :
                return SUNRISE;
            case "" :
                return NEVER;
            default :
                return Integer.parseInt(value);
        }
    }

Taken from: /server/core/src/main/java/cc/blynk/server/core/model/widgets/ui/TimeInput.java

So as per my earlier post, it looks like the time offset is no longer used.
The part we are interested in is this line:

String[] values = value.split(BODY_SEPARATOR_STRING);

Which when we find where BODY_SEPERATOR_STRING is define, which is in: /server/utils/src/main/java/cc/blynk/utils/StringUtils.java

public static final char BODY_SEPARATOR = '\0';
 public static final String BODY_SEPARATOR_STRING = String.valueOf(BODY_SEPARATOR);

We see that BODY_SEPERATOR_STRING is defined as ‘\0’ which is NULL but URL can’t encode ‘\0’, hence why we use %00.

1 Like

Thank you very very much everything is understood and working.
Now i can set my time input widget via google assistant on my cell phone

1 Like