Are multiple (PUTs) need for Turning on/off multiple lights using lights API? - philips-hue

I am using the following script: https://github.com/callil/SparkHue/blob/master/sparkhue.ino
This is working great besides the fact that it only lets me control that one light with id 3. What is I have multiple light ID's I want to turn on / off with the light API. Do I need to make multiple calls for each?
client.println("PUT /api/deviceAddress/groups/1/action HTTP/1.1");
client.println("Connection: keep-alive"); //
client.println("Host: 192.168.1.11"); //same as server
client.println("Content-Type: text/plain;charset=UTF-8"); //
client.print("Content-Length: "); //param
client.println(11+len); //brightness string + val length
client.println(); // blank line before body
client.print("{\"bri\": ");
client.print(val); //value of potentiometer
client.println("}");
Serial.println("sent");

Instead of performing individual commands on each light ID, you can create a group of multiple lights.
Assuming you want to perform a command on all your lights, you can use the all-lights-group, which has ID 0. Instead of using the /lights/3/state path, you can use a group path similarly:
/groups/0/action
To create a group you need to perform a POST on /api/<username>/groups with the IDs of the lights the group should contain and also the name of the group, but you can read it all here: Create Group API.

You could dynamically create a group, perform actions, and then remove the group again afterwards..
This might only be a smart workaround if you need to apply an action to a lot of lights.
I would probably go for just using multiple puts (one for each light if its just some few), or creating a static group.

Related

Passing More than 1000 parameters in RESTful api

Our Dashboard have dropdown which consist of more than 8k products and we have such 4-5 dropdowns.
I want to filter data based on this dropdowns.
But if I selecting all products then restful api url is breaking.
Can i use azure bus service or similar message broker service to pass this complex and multiple parameters via service and which then consumed by all apis??
While I do understand what your need is I will suggest to re-think your approach as that will lead to a better user experience.
I will use a first drop down, completely empty, that will fill in options while the user types in whatever product list you have, that way, there is only a group of items that are filled in that the user is interested in.
I will also suggest not to load anything on that drop down until the user has entered, let's say, 5 characters.
After that let the user select an item from the dropdown, and filter the second drop down and continue to use the same technique with all drop downs you have.
Let me know if you have any questions around this approach and I will be more than happy to provide an example if you don't know how to do it.
Edit:
Including samples for load dropdown lists dynamically and also another post with an example on how to return some JSON from an Azure Function that can return the data in a dynamic way like you need.
From what I can see I think it'll be helpful for you to go through several different examples that can bring you progressive knowledge to what you need to achieve, first of all it'll be nice if you know how to load items dynamically on a dropdown list:
That is a nice example, you can have an entry where the user can type
whatever products you have and then they type, lets say, more than 5
characters go and search for that data.
https://www.codebyamir.com/blog/populate-a-select-dropdown-list-with-json
This other example shows you how to return data from an azure function
with the data that you need to show the users. This is not exactly
what you need as you need to receive a parameter with what the user
typed and search in your database for the items that match that search
and return that data in a JSON format so you can use it on your web
page to show the dropdown list. I will suggest to initially hard code
a few items and return those to check that the functionality is there
and once you have that up and running move to get the actual data from
the database.
How to return a JSON object from an Azure Function with Node.js

Azure Maps Indoor Module: Change floor without user input

I've been working with the Azure maps indoor module https://learn.microsoft.com/en-us/azure/azure-maps/tutorial-creator-indoor-maps . You can allow a user to pick a level with a level control element from the library, however I cannot figure out a way to pre-set a certain level (e.g. I want to start with a certain facility and the 2nd level pre selected when the map loads.) For the facility there is a indoorManager.setFacility() function that allows you to select a facility but I have not found the equivalent for the level.
Requirement: I want to to select a level in Azure Maps without user input.
There doesn't appear to be any official way to do this yet, note that Azure Maps Creator is still in preview. That said, I did figure out a hacky way around this (may break in the future).
var facilityId = 'FCL13';
var level = 2;
//Set the facility and the levels "ordinal number". The ordinal number appears to be off by 1.
indoorManager.setFacility(facilityId, level - 1);
//Used to trigger the level control to refresh.
map.events.invoke('moveend')

what is the point of 'timeline' in array or param for get_news_feed?

I went through all tutorials and docs which stream-django provided.
And there was one thing that I could't understand.
I can't find the differences between these feed_manager methods.
# (1)
feed = feed_manager.get_news_feed('timeline', request.id)
# (2)
feed = feed_manager.get_news_feed(request.id)['timeline']
# (3)
feed = feed_manager.get_news_feed(request.id)
Could you explain the difference? Are they doing exactly same thing? timeline means flat feed, then why do we put timeline in param?
Thank you
timeline is the name of the feed group that you've created within Stream.
Once you create a feed group in Stream, you'll select the type of feed group ("flat" in this case, but can also be "aggregated" or "notification"), then, you'll name the feed group - common names are timeline/news_feed (a homepage feed showing activity from other users) or profile/user (a profile page feed showing all activities from a single user). There are no "reserved" words in feed group names.
Re: whether or not these methods are all doing the same thing:
feed_manager.get_news_feed('timeline', request.id) (1) is definitely correct. It'll fetch the feed activities for the specific timeline:1234 feed, where 1234 is most likely your user's ID.
(2) and (3) I'm not sure about - it's likely that they're doing the same thing as (1), but I'm not able to tell at the first glance at the docs.
Hopefully that helps!

How to show user's context resourcelist only

MODX Revolution 2.2.10-pl
Migx 2.6.8
I use this in a TV for my clients to be abble to choose a ressource :
{"field":"link1","caption":"Lien","inputTVtype":"resourcelist"}
The context of a user is defined with a user group context access.
I've tried to tick the checkbox of the user usergroup in the TV, but if I do that the user is not abble to see th TV anymore.
Problem is that mys client can see every ressources of every contexts. I need him to only be abble to see the resourcelist of their context. Is there a way to do that ?
You could make a TV with custom #eval options and use that for your migx field. See here for an example and description; http://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/template-variables/bindings/eval-binding.
First change your TV to this, basically just swapping out "inputTVtype" to "inputTV"
{
"field":"link1",
"caption":"Lien",
"inputTV":"yourCustomTv"
}
Step two is to create a snippet that finds the resources you want, this requires you to have some knowledge of PHP. Basically you need to find the resources and loop them, outputting a string that looks like a regular list values string (resourceId==name||resourceId==name||...)
Step three is to create "yourCustomTv", and for the input options give it the #EVAL return $modx->runSnippet('yourSnippet');

Expression engine: Maximum number of entries allowed per membrr group

Is it possible to limit the number of channel entries a member can create?
I would like to set a max number per member group.
Thanks
Yes, but it would require writing an extension. The logic would be something like this (assuming you're talking about limiting on the back-end ... from the front-end, if you're using a Safecracker entry form for example, you'd need to take a different approach):
use the sessions_end hook
check to make sure you're in the control panel ($this->EE->input->get('D') == 'cp')
check to make sure you're on the publish screen ($this->EE->input->get('C') ==
'content_publish')
query the database to see how many entries in exp_channel_titles with the channel_id of $this->EE->input->get('channel_id') belong to $this->EE->session->userdata('member_id')
if the result is greater than your allowed maximum, show them an error
That should get you started.

Resources