How can I read device state from the contents of a file?
Tommy-Jack opened this issue · 11 comments
- Issues not following the template may be closed for that reason alone.
- Operating system and version: Raspberry Pi 3 b+
- Python version: 3.7.3
- Fauxmo version (
fauxmo --version
): 0.4.9 - Echo device type (e.g. Echo, Echo Plus, Dot): Echo Dot2 and Echo Dot 3
- Echo Firmware Version:
My Issue
I can´t use the State response in the config.json
The rest of my config.json and the fauxmo is working
The Error anwere from the system
TypeError: init() got an unexpected keyword argument 'state_response_on'
WHYT
Please make sure you've taken these steps before submitting a new issue:
- [OK ] Try to reproduce the issue with Fauxmo installed in a
venv - [OK ] Ensure you're running a supported version of Python
- Requires Python >= 3.2 for Fauxmo < 0.3.0
- Requires Python >= 3.4.4 for Fauxmo >= 0.3.0
- Requires Python >= 3.6.0 for Fauxmo >= 0.4.0
- [ OK] Run Fauxmo in debug mode (
-vvv
) and include relevant output
**File "/home/pi/.venv/bin/fauxmo", line 10, in
sys.exit(cli())
File "/home/pi/.venv/lib/python3.7/site-packages/fauxmo/cli.py", line 37, in cli
main(config_path_str=args.config, verbosity=verbosity)
File "/home/pi/.venv/lib/python3.7/site-packages/fauxmo/fauxmo.py", line 120, in main
plugin = PluginClass(**plugin_vars, device)
TypeError: init() got an unexpected keyword argument 'state_response_on' - [ OK] Include your Fauxmo
config.json
- [ OK] Search the existing (including closed) issues
- [OK ] Please use codeblocks around your debug output and config
Hello Nathan,
I have your simpelHTTP.py (config File) in my "commandline.py" changing.
I want contol a Can modul on my python. This i have made and it works but now i want thats the answere came from my CAN Bus and not from the raspberry. I search a way thats make it possible.
I now also thats i dont have the "response_cmd" in my commandline.py File why i dont know how i must it write.
I want open a File on the Raspberry in thats it the answere.
It is possible that the answere can switch from a other position.
I must read this File with the config.json to answere alexa.
I hope thats you have a idee what i can do.
In the attachment you will found my Files.
Thank you for your Support and sorry for my bad english
Thanks for your response. In the future, please use codeblocks as per the issue template. Posting relevant contents from the above attached zip file:
{
"FAUXMO": {
"ip_address": "auto"
},
"PLUGINS": {
"CommandLinePlugin":{
"path": "/home/pi/commandlineplugin.py",
"DEVICES": [
{
"port": 12340,
"on_cmd": "python3 /home/pi/Speak_CAN/test1-an.py",
"off_cmd": "python3 /home/pi/Speak_CAN/test1-aus.py",
"state_cmd": "/home/pi/Speak_CAN/test1-state2",
"name": "TEST1"
},
{
"port": 12341,
"on_cmd": "python3 /home/pi/Speak_CAN/test1-an.py",
"off_cmd": "python3 /home/pi/Speak_CAN/test1-aus.py",
"name": "TEST2"
},
{
"name": "TEST3",
"port": 12342,
"on_cmd": "python3 /home/pi/Speak_CAN/test1-an.py",
"off_cmd": "python3 /home/pi/Speak_CAN/test1-aus.py"
}
]
}
}
}
I'm not sure how you're getting this error, since state_response_on
doesn't appear anywhere in your config. Are you sure that you sent the correct config file, and in its entirety?
Thanks for your effort with the English, but I have to confess that I'm having a hard time understanding what your goal and issue is; for the moment, I'm focusing on the stacktrace you provided above (re: state_response_on
).
Ok, sorry but i was in the hospital.
Are you sure that you sent the correct config file, and in its entirety?
yes this is the correct config file, i deleted the state_response. I want testing other commands so that the system gife me a answere.
In the attechment you will found a drawing. i can my light switching from two positions. one from alexa and one from a CAN-Bus Switch. Now i must change the answere when i have the light switch on by alexa and the i switch i the licht off by the CAN-Switch.
I have see in your simpleHTTP thats you read the network information from the device and gif alexa the answere back. I want to do the same, but i must it from a file. In this file is the information "light on or off".
From your simplehttpplugin.py:
def get_state(self) -> str:
"""Get device state.
Returns:
"on", "off", or "unknown"
"""
if self.state_cmd is None:
return "unknown"
req = urllib.request.Request(
url=self.state_cmd,
data=self.state_data,
headers=self.headers,
method=self.state_method,
)
When you say "Oh no this is not my problem, my fauxmo is running." is it ok. But i don´t know how can help me.
sorry but i was in the hospital
I hope everything is okay.
It sound like you want the state to be properly updated when you toggle the device status using means other than Fauxmo. That's great, and Fauxmo supports this through the get_state
method. You just have to figure out how you want your device to present its state when queried.
You should be able to read the data from a file if that's how you want to do it.
Pseudocode:
def get_state(self):
with open("state_file.txt") as f:
state = f.read()
if state in ["on", "off", "unknown"]:
return state
Hallo Nathan,
it is no all okay but i´m alive and this is the prio.
I had use the get_state Methode but is was going only for one devices.
`def get_state(self) -> str:
# if name is "Test1":
x = open('/home/pi/Speak_CAN/test1-state2', 'r')
self.SwitchState = x.read()
print ("State of " + self.name + " is " + self.SwitchState + ".")
return self.SwitchState
x.close()
if self.state_cmd is None:
return "unknown"`
I want this but for more devices in the CAN-Bus.
I must him tell that he must search for a certainly txt file and i think thats i must use for each switch its own answer file.
Example:
light living room --> answere state_living_room.txt
light bad room --> answere state_bad_room.txt
light kitchen room --> answere state_kitchen_room.txt
Can i use a if /elif??
Example:
if name =="test1": open("state_test1.txt") as f: state = f.read() if state in ["on", "off", "unknown"]: return state elif name == "test2": open("state_test2.txt") as f: state = f.read() if state in ["on", "off", "unknown"]: return state
Sure, you can use an if statement.
Please try using triple backticks (```
) for codeblocks so it preserves whitespace.
I'm glad you got it working for one device. You could probably do something clever like use the device name to help it determine which file to read:
def get_state(self) -> str:
# if name is "Test1":
with open(f'/home/pi/Speak_CAN/{self.name}-state2') as statefile:
self.SwitchState = statefile.read()
print(f"State of {self.name} is {self.SwitchState}.")
return self.SwitchState
Yes, you are my hero, that's exactly what I need. Now I have changed some names of files and information access.
Now I have to find a way to read the BUS again and again and to update the data.
But i have a Idea, I write a file that polls the bus every 10 seconds and updates the data.
Is it possible to use the {self.name} application to create files? I didn't get it.
Is it possible to use the {self.name} application to create files? I didn't get it.
I don't think I understand your question. What application?
You could customize your on()
and off()
methods to write the device name to a file, if that's what you meant.
Bump.
This issue is pending a response and is blocked until I have more info. To keep the issue list groomed, I will often close these stalled issues if they go a prolonged time without a response. In this case, I will give it another week or so.
I haven't gotten a reply, so I'm closing this issue as dead. Please feel free to let me know if I should re-open.