I am using MOCHAD to remotely control X10 lights connecting to an X10 CM15 controller. The configuration works fine and I have automated my dozen or so X10 lights/switches using HA automations.
The MOCHAD capability does not POLL the CM15 for it’s current light/switch “STATUS” (st command) and will not update HA light status to on or off (based on what the X10 CM15 thinks the status is; it does not poll either but keeps track of X10 communications over the network - the next best thing I guess).
I want to write a small program to query the status of all X10 lights from mochad (st command) and update each HA light on/off status with a more accurate state (as accurate as the CM15 knows about).
Q: What is the easiest way for a remote script to update the status of a light?
I am very new to HA and would like pointers… I’ve already written cURL scripts to update my soon-to-be deprecated WebThings home manager using it’s API so I’m 50% of the way there already.
Can you elaborate what you mean by “will not update HA light status”? If a light is turned on/off from within HA what happens, and if a light is turned on/off outside HA what happens.
In a general sense there’s not much point in trying to update the status of a sensor (or light in this case), as the integration will likely reset it wrongly again. If you’re able to query a light and detect it’s on but HA thinks it’s off, can’t you just call the turnon service? Or is it that if you turn it on from HA, a few seconds later it turns itself off?
If the light in HA is turning itself off, you could create a virtual light which you use instead, and that controls the underlying light. An MQTT light, for example, has optimistic=true to just assume turn on/off has worked. Then your script can monitor the light (for changes outside HA) and call turn on/off for your virtual switch.
In my home, X10 lights can be triggered by HA automation/GUI, or often, by manually clicking X10 buttons (by chair, bed, office, etc) . HA does not detect state changes when an X10 button is used to turn a light on/off. Note: my antique X10 switches just will not die and continue to work reliably…
HA does correctly track state if it’s used to turn X10 lights on/off.
I want to poll MOCHAD to determine current state and update HA with current X10 on/off state information. This will help keep HA in sync with the actual state of X10 devices. Polling, ever 5m or so, is better than no polling.
Your suggestion to remotely trigger the HA light entity to the current state would work, but it would also generate a bunch of extra X10 commands.
Q: What HA command / process could I use to remotely trigger an on/off command?
Preferably, I would like to just “correct” the HA light entity state to on/off and not trigger an actual X10 command. If there is a way to do this it is mo-betta.
I am still hoping someone will recommend a simple HA capability that I could use to trigger a LIGHT state to on or off using a remote program. I’m sure this is possible using multiple ways.
Here is an example of a command I use to trigger light state change using my legacy WebThings program to turn lights off/on. Is there something similar on HA?
Now, all I need to do is find the documentation for API/SERVICES and the available methods and I’ll be set.
LASTLY
The command above actually sends and executes the ON command to MOCHAD to turn the X10 light on/off.
My goal was to periodically poll MOCHAD and only UPDATE (CORRECT) HA STATE for X10 lights/switchs managed remotely by X10 MOCHAD process, not actually execute the on/off again.
Wonder if there is a way to return/display the supported verbs in API/SERVICES/LIGHT?
UPDATED: Think I found the restful API documentation here. It may allow one to update the “state” of an entity… Will have to dig further.
I am not sure what you mean by “remote script,” but I am assuming you mean something that runs separate from HA, possibly on a different physical or virtual machine.
I assume you know how to write the part of the program that does the polling to determine the state of the lights. If so, one way to communicate it to HA is via MQTT. Then, in HA, you can set up an MQTT sensor, a trigger-based template sensor, or an automation to get the state.
It’s trickier if you want to update the actual light entity that your integration isn’t updating when the light state is changed from outside HA. You could create template lights as a substitute, but that’s an extra layer of complexity above MQTT communications (or whatever other way you end up going with to communicate the light state into HA—the MQTT approach I suggested is definitely just one way).
Yes, I looked at MQTT, but that’s an additional layer/server. Docker does not support addons… I have a MQTT server in Docker already, but am not familiar with actually using it. Something for the future when I’m bored.
I previously wrote a script to monitor MOCHAD output an translate X10 state changes into remote cURL commands that trigger legacy WebThings application. I wish to port those commands to trigger HA entities which I’m migrating to.
It should be just a matter of updating the BEARER api key and replacing the restful url with what HA expects.
In my previous note, I was able to figure out how to execute a restful command on a remote system to actually turn a light on or off.
After I found the API documentation, I hope to be able to only update the state and not actually turn the device on/off.
I’ll do more testing in the next week and report back what I learned.