Change state of a sensor?

Hopefully this is an easy answer because I’m relatively new to Node Red.

I am using Insteon 6-button keypads through an ISY994i. The On/off buttons are registered as lights, however the A, B, C and D buttons register as sensors with values of 0-255. Before using the ISY994i, I used the pyinsteon integration and all 6 buttons were seen as lights and I could control them as such.

In the HA Developer Tools, I am able to set the state of the A, B, C, D buttons, and the change reflected on the actual keypad.

I’ve tried the light, HomeAssistant, switch, and isy994 domains, but haven’t been able to get the State to change. Since HA is able to do it so easily in the Developer Tools, I imagine it must be pretty simple? Any help is greatly appreciated!

So I mean you can do this. It actually isn’t super easy by design because its not really recommended but more in a sec because some of what you’re seeing confuses me.

First the how. The way to do this is to use the REST API directly. You’ll notice the HA pallette of Node RED comes with an API block. This can be used to make raw calls to the REST or websockets API of Node RED (whereas the other shapes essentially wrap these calls in a nice UX). The one you want for this is a POST to /api/states/<entity_id>, check the doc for the spec on this.

Now, why is this not recommended? HA expects state to be set from the integrations and the devices they talk to. HA essentially sees itself as essentially a view into your home. It is collecting the current up to date state information from all these things, showing it to you and letting you act on it. But it isn’t the one changing the state of these devices, its only means of interacting with them is the services the various integrations provide.

Developer tools is the one exception to this. Since it is a tool for developers it allows you to change the state of something. I never saw it explained in detail but I assume the main reason for this is testing. Like force a sensor into a specific state in order to test a scenario in your automation/script. I know that’s what I personally use it for.

But there’s some strong limitations in place when you do this:

  1. It’s completely transient. The integration will blow away your changes to the state next time it updates that sensor.
  2. It’s not persistent. If you restart HA your state changes don’t restore. As usual the sensor is unavailable until the integration provides it with an updated state.
  3. It does not do anything outside of HA. HA’s only means of interacting with external devices/services is via service calls, updating the state in dev tools isn’t reported back to the integration.

#3 is why I find what you’re describing extremely confusing. From what you’re saying the changes you make in dev tools are being reported back to the integration and are actually changing the state of the physical device. That seems very wrong to me, I don’t know why or how that would be happening.

I’m not really familiar enough with Insteon or ISY994 to know why it works this way. If that integration is wants you to change the state of sensors instead of using normal service calls then I guess you can use the REST API to do that. But that would be rather shocking as its so different from every other integration, generally any time you want to interact with the device/service you make a service call.

Just checked and you are absolutely correct - the Developer Tools doesn’t change the physical button. In that case, would the REST API result in a change outside HA?

I might have to look for a way to change the buttons to register as lights or switches instead of sensors (which makes no sense to me), just like it did with the pyinsteon integration. Or dive deeper into the isy994 domain, since it doesn’t seem to be very well documented.

No, the REST API is just an alternative way of interacting with HA. The developer tools panel for instance just calls into that REST API so if it doesn’t work from dev tools then it doesn’t work from the REST API.

Yea I feel like there’s something we’re missing for the integration. I would expect a service that does what you want it to do here. If there’s nothing in the documentation that helps you then perhaps it would be good to make a post specifically asking how to do that using services in HA. Probably a post not in the Node RED category since its not specific to node red at that point and there’s a lot of expert users that ignore this category since they don’t use Node RED.

Or alternatively could ask in the discord under integrations, that usually gets pretty quick responses.

I believe I have found a work-around for anyone in the future that comes across this problem:

  • In the ISY994 administration panel, create a new scene and add only the button to the scene.
  • Reload the integration in HA. The newly-created scene appears as a switch which can now be controlled using the Switch domain on Node Red.

Thanks so much for your help, Mike. Even though you’re not familiar with the ISY994, knowing the limitations of the developer tools helped a lot!

2 Likes